Skip to content

Instantly share code, notes, and snippets.

@r6m
Forked from atedja/golang-json-stream-decoder
Created January 2, 2018 17:48
Show Gist options
  • Save r6m/b6db25eda1244f4b0b86b44a368ee9c2 to your computer and use it in GitHub Desktop.
Save r6m/b6db25eda1244f4b0b86b44a368ee9c2 to your computer and use it in GitHub Desktop.
Example of using JSON Stream Decoder from STDIN
package main
import (
"encoding/json"
"fmt"
"os"
)
func main() {
decoder := json.NewDecoder(os.Stdin)
decoder.UseNumber()
json := make(map[string]interface{})
for {
err := decoder.Decode(&json)
if err != nil {
fmt.Println("caught error")
fmt.Println(err)
} else {
fmt.Println("JSON is:")
fmt.Println(json)
json = make(map[string]interface{})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment