Skip to content

Instantly share code, notes, and snippets.

@tbillington
Created January 20, 2015 22:30
Show Gist options
  • Save tbillington/8dd788764ff1bba3bc8e to your computer and use it in GitHub Desktop.
Save tbillington/8dd788764ff1bba3bc8e to your computer and use it in GitHub Desktop.
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