Output format
Flags to control yaml and json output format
These flags are available for all
yq
commands.By default,
yq
prints with colours if it detects a terminal. You can manually change this by using eitherThe
--colors/-C
flag to force print with colors.The
--no-colors/-M
flag to force print without coloursTo print out idiomatic
yaml
use the --prettyPrint/-P
flag. Note that this is shorthand for using the style operator ... style=""
Use the indent flag
--indent/-I
to control the number of spaces used for indentation. This also works for JSON output. The default value is 2.Note that lists are indented at the same level as the map key at indent level 2, but are more deeply indented at indent level 4 and greater. This is (currently) a quirk of the underlying yaml parser.
Given:
apples:
collection:
- name: Green
- name: Blue
favourite: Pink Lady
Then:
yq -I4 sample.yaml
Will print out:
apples:
collection:
- name: Green
- name: Blue
favourite: Pink Lady
This also works with json
yq -j -I4 sample.yaml
yields
{
"apples": {
"collection": [
{
"name": "Green"
},
{
"name": "Blue"
}
],
"favourite": "Pink Lady"
}
}
By default scalar values are 'unwrapped', that is only their value is printed (except when outputting as JSON). To print out the node as-is, with the original formatting an any comments pass in
--unwrapScalar=false
Given data.yml:
a: "Things" # cool stuff
Then:
yq --unwrapScalar=false '.a' data.yml
Will yield:
"Things" # cool stuff
where as without setting the flag to false you would get:
Things
Last modified 9mo ago