Skip to content

Instantly share code, notes, and snippets.

@k82cn
Created April 7, 2017 04:52
Show Gist options
  • Save k82cn/5081f64d160dc166e29dc2d0ac4e057b to your computer and use it in GitHub Desktop.
Save k82cn/5081f64d160dc166e29dc2d0ac4e057b to your computer and use it in GitHub Desktop.
An example of json in golang.
package main
import (
"encoding/json"
"fmt"
)
func main() {
var jsonBlob = []byte(`[
{"Name": "Platypus", "Order": "Monotremata"},
{"Name": "Quoll", "Order": "Dasyuromorphia"}
]`)
type Animal struct {
Name string `json:"name"`
Order string `json:"order"`
}
var animals []Animal
json.Unmarshal(jsonBlob, &animals)
fmt.Printf("%+v\n", animals)
str, _ := json.Marshal(animals[0])
fmt.Printf("%+v\n", string(str))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment