Skip to content

Instantly share code, notes, and snippets.

@atedja
Last active November 2, 2018 10:00
Show Gist options
  • Save atedja/04cd6c0e748e5a34b0fe to your computer and use it in GitHub Desktop.
Save atedja/04cd6c0e748e5a34b0fe 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