Zest.

Go: JSON encode and decode

A short, tested Go example for json encode and decode. Copy it and adjust the names and paths for your project.

Go
type Item struct {
    ID   int    `json:"id"`
    Name string `json:"name"`
}

b, _ := json.Marshal(Item{1, "zest"})

var it Item
err := json.Unmarshal(b, &it)

Find it in Zest

Search for “go json encode and decode” in Zest and this example appears above the results, with other matches to choose from. Searches stay private.

More Go examples

All Go examples