This Commented CUE
demonstrates how to use the built-in function
encoding/json.Indent
to transform JSON from a compact, single-line form held in a string into JSON
with insignificant whitespace added that makes it easier for humans to read.
file.cue
package example
import "encoding/json"
// See Related content, below, for documentation
// of json.Indent's 3 arguments:
// func Indent(src []byte, prefix, indent string)
indent: json.Indent(jsonString, " ", " ")
jsonString: #"{"a":1,"b":{"c":"two","d":3.0},"e":false,"f":[4,5.0,"A\nMulti\nLine\nString"]}"#
TERMINAL
$ cue export -e indent --out text
{
"a": 1,
"b": {
"c": "two",
"d": 3.0
},
"e": false,
"f": [
4,
5.0,
"A\nMulti\nLine\nString"
]
}
Related content
encoding/json.Indent
documents the function’s arguments- The
encoding/json
built-in package