json.Unmarshal
The Go function that decodes JSON bytes into a Go value you pass by pointer, such as &reply.
In more detail
Fields are matched to keys through struct tags or by name. Syntax errors and type mismatches return an error; unknown keys are ignored unless you use a Decoder with DisallowUnknownFields. Decode into typed structs so the rest of the code gets checked values.
Example
err := json.Unmarshal(data, &reply)Related terms
- json.Marshal — The Go function that encodes a value, such as a struct or slice, into JSON bytes.
- encoding/json — Go's standard library package for converting between Go values and JSON text.
- struct tag — A string in backquotes after a struct field, such as `json:"status"`, that tells encoders like encoding/json how to name or treat that field.
- untrusted input — Any data a program did not create itself, including arguments, form fields, request bodies, file contents, file names and environment variables.
- pointer — A value that stores the memory location of another piece of data, so the program can follow it to that data.
Taught in
- Parsing JSON with encoding/json — Concurrent Systems Programming with Go