Equals
This is a boolean operator that will return true if the LHS is equal to the RHS and false otherwise.
.a == .bIt is most often used with the select operator to find particular nodes:
select(.a == .b)The not equals != operator returns false if the LHS is equal to the RHS.
Related Operators
Match string
Given a sample.yml file of:
- cat
- goat
- dogthen
yq '.[] | (. == "*at")' sample.ymlwill output
true
true
falseDon't match string
Given a sample.yml file of:
- cat
- goat
- dogthen
yq '.[] | (. != "*at")' sample.ymlwill output
false
false
trueMatch number
Given a sample.yml file of:
- 3
- 4
- 5then
yq '.[] | (. == 4)' sample.ymlwill output
false
true
falseDon't match number
Given a sample.yml file of:
- 3
- 4
- 5then
yq '.[] | (. != 4)' sample.ymlwill output
true
false
trueMatch nulls
Running
yq --null-input 'null == ~'will output
trueNon existent key doesn't equal a value
Given a sample.yml file of:
a: frogthen
yq 'select(.b != "thing")' sample.ymlwill output
a: frogTwo non existent keys are equal
Given a sample.yml file of:
a: frogthen
yq 'select(.b == .c)' sample.ymlwill output
a: frogLast updated
Was this helpful?