y
y
yq
Search…
Equals
This is a boolean operator that will return true if the LHS is equal to the RHS and false otherwise.
1
.a == .b
Copied!
It is most often used with the select operator to find particular nodes:
1
select(.a == .b)
Copied!
The not equals != operator returns false if the LHS is equal to the RHS.

Related Operators

  • comparison (>=, < etc) operators here
  • boolean operators (and, or, any etc) here
  • select operator here
Note that versions prior to 4.18 require the 'eval/e' command to be specified.
yq e <exp> <file>

Match string

Given a sample.yml file of:
1
- cat
2
- goat
3
- dog
Copied!
then
1
yq '.[] | (. == "*at")' sample.yml
Copied!
will output
1
true
2
true
3
false
Copied!

Don't match string

Given a sample.yml file of:
1
- cat
2
- goat
3
- dog
Copied!
then
1
yq '.[] | (. != "*at")' sample.yml
Copied!
will output
1
false
2
false
3
true
Copied!

Match number

Given a sample.yml file of:
1
- 3
2
- 4
3
- 5
Copied!
then
1
yq '.[] | (. == 4)' sample.yml
Copied!
will output
1
false
2
true
3
false
Copied!

Don't match number

Given a sample.yml file of:
1
- 3
2
- 4
3
- 5
Copied!
then
1
yq '.[] | (. != 4)' sample.yml
Copied!
will output
1
true
2
false
3
true
Copied!

Match nulls

Running
1
yq --null-input 'null == ~'
Copied!
will output
1
true
Copied!

Non existent key doesn't equal a value

Given a sample.yml file of:
1
a: frog
Copied!
then
1
yq 'select(.b != "thing")' sample.yml
Copied!
will output
1
a: frog
Copied!

Two non existent keys are equal

Given a sample.yml file of:
1
a: frog
Copied!
then
1
yq 'select(.b == .c)' sample.yml
Copied!
will output
1
a: frog
Copied!