Working with JSON
Yaml to Json
To convert output to json, use the --tojson
(or -j
) flag. This is supported by all commands. You can change the json output format by using the pretty print or indent flags. Note that due to the implementation of the JSON marshaller in GO, object keys will be sorted on output (https://golang.org/pkg/encoding/json/#Marshal).
Given a sample.yaml file of:
then
will output
To format the json:
will yield
Multiple matches
Each matching yaml node will be converted to json and printed out on a separate line. The prettyPrint and indent flags will still work too.
Given a sample.yaml file of:
then
will output
Json to Yaml
To read in json, just pass in a json file instead of yaml, it will just work - as json is a subset of yaml. However, you will probably want to pretty print the output to look more like an idiomatic yaml document.
e.g given a json file
then
will output
Last updated