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!

Match string

Given a sample.yml file of:
1
- cat
2
- goat
3
- dog
Copied!
then
1
yq eval '.[] | (. == "*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 eval '.[] | (. != "*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 eval '.[] | (. == 4)' sample.yml
Copied!
will output
1
false
2
true
3
false
Copied!

Dont match number

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

Match nulls

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

Non exisitant key doesn't equal a value

Given a sample.yml file of:
1
a: frog
Copied!
then
1
yq eval '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 eval 'select(.b == .c)' sample.yml
Copied!
will output
1
a: frog
Copied!
Last modified 1mo ago