Alternative (Default value)
This operator is used to provide alternative (or default) values when a particular expression is either null or false.
Given a sample.yml file of:
a: bridge
then
yq '.a // "hello"' sample.yml
will output
bridge
Given a sample.yml file of:
{}
then
yq '.a // "hello"' sample.yml
will output
hello
Given a sample.yml file of:
a: ~
then
yq '.a // "hello"' sample.yml
will output
hello
Given a sample.yml file of:
a: false
then
yq '.a // "hello"' sample.yml
will output
hello
Given a sample.yml file of:
a: false
b: cat
then
yq '.a // .b' sample.yml
will output
cat
This initialises
a
if it's not presentGiven a sample.yml file of:
a: 1
then
yq '(.a // (.a = 0)) += 1' sample.yml
will output
a: 2
This initialises
a
if it's not presentGiven a sample.yml file of:
b: camel
then
yq '(.a // (.a = 0)) += 1' sample.yml
will output
b: camel
a: 1
Last modified 10mo ago