json.Encoder

A Go value that writes JSON to an io.Writer, such as standard output, with optional indentation for human readers.

In more detail

json.NewEncoder(os.Stdout).Encode(report) writes one value followed by a new line. SetIndent("", " ") makes it readable for people; leave it off for machines. Keep machine output on standard output and diagnostics on standard error.

Example

encoder := json.NewEncoder(os.Stdout)
encoder.SetIndent("", "  ")
encoder.Encode(report)

Related terms

Taught in

References