yq/pkg/yqlib/doc/Style Operator.md
2020-11-18 20:42:37 +11:00

2.2 KiB

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

Examples

Set tagged style

Given a sample.yml file of:

a: cat
b: 5
c: 3.2
e: true

then

yq eval '.. style="tagged"' sample.yml

will output

!!map
a: !!str cat
b: !!int 5
c: !!float 3.2
e: !!bool true

Set double quote style

Given a sample.yml file of:

a: cat
b: 5
c: 3.2
e: true

then

yq eval '.. style="double"' sample.yml

will output

a: "cat"
b: "5"
c: "3.2"
e: "true"

Set single quote style

Given a sample.yml file of:

a: cat
b: 5
c: 3.2
e: true

then

yq eval '.. style="single"' sample.yml

will output

a: 'cat'
b: '5'
c: '3.2'
e: 'true'

Set literal quote style

Given a sample.yml file of:

a: cat
b: 5
c: 3.2
e: true

then

yq eval '.. style="literal"' sample.yml

will output

a: |-
  cat  
b: |-
  5  
c: |-
  3.2  
e: |-
  true  

Set folded quote style

Given a sample.yml file of:

a: cat
b: 5
c: 3.2
e: true

then

yq eval '.. style="folded"' sample.yml

will output

a: >-
  cat  
b: >-
  5  
c: >-
  3.2  
e: >-
  true  

Set flow quote style

Given a sample.yml file of:

a: cat
b: 5
c: 3.2
e: true

then

yq eval '.. style="flow"' sample.yml

will output

{a: cat, b: 5, c: 3.2, e: true}

Set empty (default) quote style

Given a sample.yml file of:

a: cat
b: 5
c: 3.2
e: true

then

yq eval '.. style=""' sample.yml

will output

a: cat
b: 5
c: 3.2
e: true

Set style using a path

Given a sample.yml file of:

a: cat
b: double

then

yq eval '.a style=.b' sample.yml

will output

a: "cat"
b: double

Example 8

Given a sample.yml file of:

a: cat
b: dog

then

yq eval '.. style=""' sample.yml

will output

a: cat
b: dog

Example 9

Given a sample.yml file of:

a: cat
b: thing

then

yq eval '.. | style' sample.yml

will output




Example 10

Given a sample.yml file of:

a: cat

then

yq eval '.. | style' sample.yml

will output