Created
November 28, 2019 13:09
-
-
Save ei-grad/6fff88a01c3c51edce49ee71d00cc296 to your computer and use it in GitHub Desktop.
Convert large JSON array to lines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"log" | |
"os" | |
) | |
func main() { | |
dec := json.NewDecoder(os.Stdin) | |
enc := json.NewEncoder(os.Stdout) | |
_, err := dec.Token() | |
if err != nil { | |
log.Fatal(err) | |
} | |
for { | |
var v map[string]interface{} | |
if err := dec.Decode(&v); err != nil { | |
log.Println(err) | |
return | |
} | |
if err := enc.Encode(&v); err != nil { | |
log.Println(err) | |
} | |
fmt.Println() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment