Skip to content

Instantly share code, notes, and snippets.

@julianshen
Created September 13, 2015 08:55
Show Gist options
  • Save julianshen/2416ee3dc15c7358340f to your computer and use it in GitHub Desktop.
Save julianshen/2416ee3dc15c7358340f to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"fmt"
"os"
)
func main() {
type User struct {
ObjectId, SessionToken, Username string
}
fileReader, err := os.Open("_User.json")
if err != nil {
panic(err)
}
defer fileReader.Close()
dec := json.NewDecoder(fileReader)
// read open bracket
for {
t, err := dec.Token()
if err != nil {
panic(err)
}
d, ok := t.(json.Delim)
if ok && d.String() == "[" {
break
}
}
var m User
// while the array contains values
for dec.More() {
// decode an array value (User)
err := dec.Decode(&m)
if err != nil {
panic(err)
}
fmt.Printf("%v: %v: %v\n", m.ObjectId, m.Username, m.SessionToken)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment