Created
January 20, 2015 22:30
-
-
Save tbillington/8dd788764ff1bba3bc8e to your computer and use it in GitHub Desktop.
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" | |
"io" | |
"log" | |
"strings" | |
) | |
func main() { | |
const jsonStream = ` | |
{"Name": "Ed", "Text": "Knock knock."} | |
{"Name": "Sam", "Text": "Who's there?"} | |
{"Name": "Ed", "Text": "Go fmt."} | |
{"Name": "Sam", "Text": "Go fmt who?"} | |
{"Name": "Ed", "Text": "Go fmt yourself!"} | |
` | |
type Message map[string]interface{} | |
dec := json.NewDecoder(strings.NewReader(jsonStream)) | |
for { | |
var m Message | |
if err := dec.Decode(&m); err == io.EOF { | |
break | |
} else if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Printf("%s\n", m) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment