Convert
Yaml to Json¶
To convert output to json, use the --tojson (or -j) flag. This is supported by all commands.
Each matching yaml node will be converted to json and printed out on a separate line.
Given a sample.yaml file of:
b:
c: 2
then
yq r -j sample.yaml
will output
{"b":{"c":2}}
Given a sample.yaml file of:
bob:
c: 2
bab:
c: 5
then
yq r -j sample.yaml b*
will output
{"c":2}
{"c":5}
Json to Yaml¶
To read in json, just pass in a json file instead of yaml, it will just work :)
e.g given a json file
{"a":"Easy! as one two three","b":{"c":2,"d":[3,4]}}
then
yq r sample.json
will output
a: Easy! as one two three
b:
c: 2
d:
- 3
- 4