Last active
November 2, 2018 10:00
-
-
Save atedja/04cd6c0e748e5a34b0fe to your computer and use it in GitHub Desktop.
Example of using JSON Stream Decoder from STDIN
This file contains 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" | |
"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