pkg/yqlib/doc/operators/style.md
The style operator can be used to get or set the style of nodes (e.g. string style, yaml style). Use this to control the formatting of the document in yaml.
Given a sample.yml file of:
a:
b: thing
c: something
then
yq '.a.b = "new" | .a.b style="double"' sample.yml
will output
a:
b: "new"
c: something
Given a sample.yml file of:
a:
b: thing
c: something
then
yq 'with(.a.b ; . = "new" | . style="double")' sample.yml
will output
a:
b: "new"
c: something
Given a sample.yml file of:
a: cat
b: 5
c: 3.2
e: true
f:
- 1
- 2
- 3
g:
something: cool
then
yq '.. style="tagged"' sample.yml
will output
!!map
a: !!str cat
b: !!int 5
c: !!float 3.2
e: !!bool true
f: !!seq
- !!int 1
- !!int 2
- !!int 3
g: !!map
something: !!str cool
Given a sample.yml file of:
a: cat
b: 5
c: 3.2
e: true
f:
- 1
- 2
- 3
g:
something: cool
then
yq '.. style="double"' sample.yml
will output
a: "cat"
b: "5"
c: "3.2"
e: "true"
f:
- "1"
- "2"
- "3"
g:
something: "cool"
Given a sample.yml file of:
a: cat
b: 5
c: 3.2
e: true
f:
- 1
- 2
- 3
g:
something: cool
then
yq '... style="double"' sample.yml
will output
"a": "cat"
"b": "5"
"c": "3.2"
"e": "true"
"f":
- "1"
- "2"
- "3"
"g":
"something": "cool"
Given a sample.yml file of:
a: cat
b: 5
c: 3.2
e: true
f:
- 1
- 2
- 3
g:
something: cool
then
yq '.. style="single"' sample.yml
will output
a: 'cat'
b: '5'
c: '3.2'
e: 'true'
f:
- '1'
- '2'
- '3'
g:
something: 'cool'
Given a sample.yml file of:
a: cat
b: 5
c: 3.2
e: true
f:
- 1
- 2
- 3
g:
something: cool
then
yq '.. style="literal"' sample.yml
will output
a: |-
cat
b: |-
5
c: |-
3.2
e: |-
true
f:
- |-
1
- |-
2
- |-
3
g:
something: |-
cool
Given a sample.yml file of:
a: cat
b: 5
c: 3.2
e: true
f:
- 1
- 2
- 3
g:
something: cool
then
yq '.. style="folded"' sample.yml
will output
a: >-
cat
b: >-
5
c: >-
3.2
e: >-
true
f:
- >-
1
- >-
2
- >-
3
g:
something: >-
cool
Given a sample.yml file of:
a: cat
b: 5
c: 3.2
e: true
f:
- 1
- 2
- 3
g:
something: cool
then
yq '.. style="flow"' sample.yml
will output
{a: cat, b: 5, c: 3.2, e: true, f: [1, 2, 3], g: {something: cool}}
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:
{a: cat, "b": 5, 'c': 3.2, "e": true, f: [1,2,3], "g": { something: "cool"} }
then
yq '... style=""' sample.yml
will output
a: cat
b: 5
c: 3.2
e: true
f:
- 1
- 2
- 3
g:
something: cool
Given a sample.yml file of:
a: single
b: double
then
yq '.[] style |= .' sample.yml
will output
a: 'single'
b: "double"
Given a sample.yml file of:
{a: "cat", b: 'thing'}
then
yq '.. | style' sample.yml
will output
flow
double
single