Skip to content

Instantly share code, notes, and snippets.

@lachlan-eagling
Created October 12, 2019 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lachlan-eagling/14c27855e149114855fa6b1ff48d3b7e to your computer and use it in GitHub Desktop.
Save lachlan-eagling/14c27855e149114855fa6b1ff48d3b7e to your computer and use it in GitHub Desktop.
Blog - Anatomy of a Struct (Unmarshaling Array)
func main() {
var users []User
userJson := []byte(`[{"firstName": "Lachlan", "surname": "Eagling", "username": "Lachlan_E", "age": 28}, {"firstName": "Jon", "surname": "Snow", "username": "Watcher21", "age": 20}]`)
if err := json.Unmarshal(userJson, &users); err != nil {
fmt.Println(err)
}
fmt.Println(users)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment