JSON in Go
Go makes it incredibly easy to work with JSON using the encoding/json package.
1. Marshalling (Go to JSON)
Converting a Go struct or map into a JSON string.
2. Unmarshalling (JSON to Go)
Converting a JSON string back into a Go struct.
3. Maps for Dynamic JSON
If you don't know the keys in advance, use a map.
4. Struct Tags
Struct tags (the text in backticks) tell the JSON package how to name the fields in the output.
json:"name": Use "name" instead of the Go variable name.json:"-": Ignore this field completely.json:"id,omitempty": Don't include this field if it's empty (0, "", nil).
Using Encoder and Decoder
If you are reading from a network connection or a file, use Encoder and Decoder as they work directly with streams.