Output format
Flags to control yaml and json output format
These flags are available for all yq
commands.
Colorize Output
Use the --colors/-C
flag to print out yaml with colors. This does not work when outputing in JSON format.
Pretty Print
Use the --prettyPrint/-P
flag to enforce a formatting style for yaml documents. This is particularly useful when reading a json file (which is a subset of yaml) and wanting to format it in a more conventional yaml format.
Given:
Then:
Will print out:
This works in the same manner for yaml files:
will format to:
Indent
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.
Given:
Then:
Will print out:
With json, you must also specify the --prettyPrint/-P
flag
yields
Unwrap scalars
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:
Then:
yq r --unwrapScalar=false data.yml a
Will yield:
where as without setting the flag to false you would get:
Strip comments
Use the --stripComments
flag to print out the yaml file without any of the original comments.
Given data.yml of:
Then
Will yield:
Last updated
Was this helpful?