y
y
yq
Search…
Style
The style operator can be used to get or set the style of nodes (e.g. string style, yaml style)

Update and set style of a particular node (simple)

Given a sample.yml file of:
1
a:
2
b: thing
3
c: something
Copied!
then
1
yq eval '.a.b = "new" | .a.b style="double"' sample.yml
Copied!
will output
1
a:
2
b: "new"
3
c: something
Copied!

Update and set style of a particular node using path variables

Given a sample.yml file of:
1
a:
2
b: thing
3
c: something
Copied!
then
1
yq eval 'with(.a.b ; . = "new" | . style="double")' sample.yml
Copied!
will output
1
a:
2
b: "new"
3
c: something
Copied!

Set tagged style

Given a sample.yml file of:
1
a: cat
2
b: 5
3
c: 3.2
4
e: true
Copied!
then
1
yq eval '.. style="tagged"' sample.yml
Copied!
will output
1
!!map
2
a: !!str cat
3
b: !!int 5
4
c: !!float 3.2
5
e: !!bool true
Copied!

Set double quote style

Given a sample.yml file of:
1
a: cat
2
b: 5
3
c: 3.2
4
e: true
Copied!
then
1
yq eval '.. style="double"' sample.yml
Copied!
will output
1
a: "cat"
2
b: "5"
3
c: "3.2"
4
e: "true"
Copied!

Set double quote style on map keys too

Given a sample.yml file of:
1
a: cat
2
b: 5
3
c: 3.2
4
e: true
Copied!
then
1
yq eval '... style="double"' sample.yml
Copied!
will output
1
"a": "cat"
2
"b": "5"
3
"c": "3.2"
4
"e": "true"
Copied!

Set single quote style

Given a sample.yml file of:
1
a: cat
2
b: 5
3
c: 3.2
4
e: true
Copied!
then
1
yq eval '.. style="single"' sample.yml
Copied!
will output
1
a: 'cat'
2
b: '5'
3
c: '3.2'
4
e: 'true'
Copied!

Set literal quote style

Given a sample.yml file of:
1
a: cat
2
b: 5
3
c: 3.2
4
e: true
Copied!
then
1
yq eval '.. style="literal"' sample.yml
Copied!
will output
1
a: |-
2
cat
3
b: |-
4
5
5
c: |-
6
3.2
7
e: |-
8
true
Copied!

Set folded quote style

Given a sample.yml file of:
1
a: cat
2
b: 5
3
c: 3.2
4
e: true
Copied!
then
1
yq eval '.. style="folded"' sample.yml
Copied!
will output
1
a: >-
2
cat
3
b: >-
4
5
5
c: >-
6
3.2
7
e: >-
8
true
Copied!

Set flow quote style

Given a sample.yml file of:
1
a: cat
2
b: 5
3
c: 3.2
4
e: true
Copied!
then
1
yq eval '.. style="flow"' sample.yml
Copied!
will output
1
{a: cat, b: 5, c: 3.2, e: true}
Copied!

Reset style - or pretty print

Set empty (default) quote style, note the usage of ... to match keys too. Note that there is a --prettyPrint/-P short flag for this.
Given a sample.yml file of:
1
a: cat
2
"b": 5
3
'c': 3.2
4
"e": true
Copied!
then
1
yq eval '... style=""' sample.yml
Copied!
will output
1
a: cat
2
b: 5
3
c: 3.2
4
e: true
Copied!

Set style relatively with assign-update

Given a sample.yml file of:
1
a: single
2
b: double
Copied!
then
1
yq eval '.[] style |= .' sample.yml
Copied!
will output
1
a: 'single'
2
b: "double"
Copied!

Read style

Given a sample.yml file of:
1
{a: "cat", b: 'thing'}
Copied!
then
1
yq eval '.. | style' sample.yml
Copied!
will output
1
flow
2
double
3
single
Copied!