json.Marshal

The Go function that encodes a value, such as a struct or slice, into JSON bytes.

In more detail

It returns the bytes and an error, and uses struct tags for key names. Only exported fields are included. For output to a stream such as standard output, json.NewEncoder writes directly instead.

Example

report, err := json.Marshal(Report{Host: "api", Healthy: true})

Related terms

Taught in

References