This Commented CUE
demonstrates how to use the built-in function
encoding/json.Compact
to transform JSON held in a string into a single line of JSON with all
insignificant whitespace removed.
file.cue
package example
import "encoding/json"
compact: json.Compact(jsonString)
// jsonString contains insignificant whitespace,
// split over several lines.
jsonString: #"""
{
"a": 1,
"b": {
"c": "two",
"d": 3.0
},
"e": false,
"f": [
4,
5.0,
"A\nMulti\nLine\nString"
]
}
"""#
TERMINAL
$ cue export -e compact --out text
{"a":1,"b":{"c":"two","d":3.0},"e":false,"f":[4,5.0,"A\nMulti\nLine\nString"]}
Related content
- The
encoding/json
built-in package