snippetgoCritical
How can I pretty-print JSON using Go?
Viewed 0 times
howprettyusingprintcanjson
Problem
Does anyone know of a simple way to pretty-print JSON output in Go?
I'd like to pretty-print the result of
I'd like to pretty-print the result of
json.Marshal, as well as formatting an existing string of JSON so it's easier to read.Solution
MarshalIndent will allow you to output your JSON with indentation and spacing. For example:{
"data": 1234
}The
indent argument specifies the series of characters to indent with. Thus, json.MarshalIndent(data, "", " ") will pretty-print using four spaces for indentation.Code Snippets
{
"data": 1234
}Context
Stack Overflow Q#19038598, score: 533
Revisions (0)
No revisions yet.