Style

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.

Update and set style of a particular node (simple)

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

Update and set style of a particular node using path variables

Given a sample.yml file of:

a:
  b: thing
  c: something

then

will output

Set tagged style

Given a sample.yml file of:

then

will output

Set double quote style

Given a sample.yml file of:

then

will output

Set double quote style on map keys too

Given a sample.yml file of:

then

will output

Set single quote style

Given a sample.yml file of:

then

will output

Set literal quote style

Given a sample.yml file of:

then

will output

Set folded quote style

Given a sample.yml file of:

then

will output

Set flow quote style

Given a sample.yml file of:

then

will output

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:

then

will output

Set style relatively with assign-update

Given a sample.yml file of:

then

will output

Read style

Given a sample.yml file of:

then

will output

Last updated

Was this helpful?