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 file 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(json.Marshal(input), " ", " ")
// The contents of data.json is placed here by
// the -l parameter.
input: _
data.json
{"a":1,"b":{"c":"two","d":3.0},"e":false,"f":[4,5.0,"A\nMulti\nLine\nString"]}
TERMINAL
$ cue export file.cue -l input: data.json -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