The style operator can be used to get or set the style of nodes (e.g. string style, yaml style)
Given a sample.yml file of:
a: catb: 5c: 3.2e: true
then
yq eval '.. style="tagged"' sample.yml
will output
!!mapa: !!str catb: !!int 5c: !!float 3.2e: !!bool true
Given a sample.yml file of:
a: catb: 5c: 3.2e: true
then
yq eval '.. style="double"' sample.yml
will output
a: "cat"b: "5"c: "3.2"e: "true"
Given a sample.yml file of:
a: catb: 5c: 3.2e: true
then
yq eval '... style="double"' sample.yml
will output
"a": "cat""b": "5""c": "3.2""e": "true"
Given a sample.yml file of:
a: catb: 5c: 3.2e: true
then
yq eval '.. style="single"' sample.yml
will output
a: 'cat'b: '5'c: '3.2'e: 'true'
Given a sample.yml file of:
a: catb: 5c: 3.2e: true
then
yq eval '.. style="literal"' sample.yml
will output
a: |-catb: |-5c: |-3.2e: |-true
Given a sample.yml file of:
a: catb: 5c: 3.2e: true
then
yq eval '.. style="folded"' sample.yml
will output
a: >-catb: >-5c: >-3.2e: >-true
Given a sample.yml file of:
a: catb: 5c: 3.2e: true
then
yq eval '.. style="flow"' sample.yml
will output
{a: cat, b: 5, c: 3.2, e: true}
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
then
yq eval '... style=""' sample.yml
will output
a: catb: 5c: 3.2e: true
Given a sample.yml file of:
a: singleb: double
then
yq eval '.[] style |= .' sample.yml
will output
a: 'single'b: "double"
Given a sample.yml file of:
{a: "cat", b: 'thing'}
then
yq eval '.. | style' sample.yml
will output
flowdoublesingle