y
y
yq
Search…
Output format
Flags to control yaml and json output format
These flags are available for all yq commands.

Color

By default, yq prints with colours if it detects a terminal. You can manully this by using either
The --colors/-Cflag to force print with colors.
The `--no-colors/-M flag to force print without colours

Pretty Print

To print out idiomatic yaml use the --prettyPrint/-P flag. Note that this is shorthand for using the style operator ... style=""

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.
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:
1
apples:
2
collection:
3
- name: Green
4
- name: Blue
5
favourite: Pink Lady
Copied!
Then:
1
yq e -I4 sample.yaml
Copied!
Will print out:
1
apples:
2
collection:
3
- name: Green
4
- name: Blue
5
favourite: Pink Lady
Copied!
This also works with json
1
yq e -j -I4 sample.yaml
Copied!
yields
1
{
2
"apples": {
3
"collection": [
4
{
5
"name": "Green"
6
},
7
{
8
"name": "Blue"
9
}
10
],
11
"favourite": "Pink Lady"
12
}
13
}
Copied!

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:
1
a: "Things" # cool stuff
Copied!
Then:
yq e --unwrapScalar=false '.a' data.yml
Will yield:
1
"Things" # cool stuff
Copied!
where as without setting the flag to false you would get:
1
Things
Copied!
Last modified 5mo ago