encoding/json
Go's standard library package for converting between Go values and JSON text.
In more detail
json.Marshal and json.Unmarshal convert whole values at once; json.NewEncoder and json.NewDecoder work on streams. It only sees exported struct fields, and struct tags control the JSON key names. Malformed input comes back as an error, never a half-filled guess.
Example
import "encoding/json"Related terms
- json.Marshal — The Go function that encodes a value, such as a struct or slice, into JSON bytes.
- json.Unmarshal — The Go function that decodes JSON bytes into a Go value you pass by pointer, such as &reply.
- json.Encoder — A Go value that writes JSON to an io.Writer, such as standard output, with optional indentation for human readers.
- 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.
- exported identifier — A name in Go that starts with a capital letter, which makes it visible to code in other packages.
- JSON — A simple text format for structured data made of keys, values, lists and nested objects.
Taught in
- Parsing JSON with encoding/json — Concurrent Systems Programming with Go
- Exporting Results as JSON — Concurrent Systems Programming with Go