yq
v4.x
v4.x
  • yq
  • How It Works
  • Recipes
  • Upgrading from V3
  • Commands
    • Evaluate
    • Evaluate All
    • Shell Completion
  • Operators
    • Add
    • Alternative (Default value)
    • Anchor and Alias Operators
    • Array to Map
    • Assign (Update)
    • Boolean Operators
    • Collect into Array
    • Column
    • Comment Operators
    • Compare Operators
    • Contains
    • Create, Collect into Object
    • Date Time
    • Delete
    • Divide
    • Document Index
    • Encode / Decode
    • Entries
    • Env Variable Operators
    • Equals
    • Eval
    • File Operators
    • Filter Operator
    • Flatten
    • Group By
    • Has
    • Keys
    • Kind
    • Length
    • Line
    • Load
    • Min
    • Map
    • Max
    • Modulo
    • Multiply (Merge)
    • Omit
    • Parent
    • Path
    • Pick
    • Pipe
    • Pivot
    • Recursive Descent (Glob)
    • Reduce
    • Reverse
    • Select
    • Shuffle
    • Slice Array
    • Sort
    • Sort Keys
    • Split into Documents
    • String Operators
    • Style
    • Subtract
    • Tag
    • To Number
    • Traverse (Read)
    • Union
    • Unique
    • Variable Operators
    • With
  • Usage
    • Output format
    • Working with CSV, TSV
    • Working with JSON
    • Working with Properties
    • Working with XML
    • Working with LUA
    • Working with TOML
    • Working with Shell Output
    • Front Matter
    • Split into multiple files
    • GitHub Action
    • Tips, Tricks, Troubleshooting
  • Github Page
Powered by GitBook
On this page
  • Related Operators
  • Match string
  • Don't match string
  • Match number
  • Don't match number
  • Match nulls
  • Non existent key doesn't equal a value
  • Two non existent keys are equal

Was this helpful?

  1. Operators

Equals

PreviousEnv Variable OperatorsNextEval

Last updated 2 years ago

Was this helpful?

This is a boolean operator that will return true if the LHS is equal to the RHS and false otherwise.

.a == .b

It 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

  • comparison (>=, < etc) operators

  • boolean operators (and, or, any etc)

  • select operator

Match string

Given a sample.yml file of:

- cat
- goat
- dog

then

yq '.[] | (. == "*at")' sample.yml

will output

true
true
false

Don't match string

Given a sample.yml file of:

- cat
- goat
- dog

then

yq '.[] | (. != "*at")' sample.yml

will output

false
false
true

Match number

Given a sample.yml file of:

- 3
- 4
- 5

then

yq '.[] | (. == 4)' sample.yml

will output

false
true
false

Don't match number

Given a sample.yml file of:

- 3
- 4
- 5

then

yq '.[] | (. != 4)' sample.yml

will output

true
false
true

Match nulls

Running

yq --null-input 'null == ~'

will output

true

Non existent key doesn't equal a value

Given a sample.yml file of:

a: frog

then

yq 'select(.b != "thing")' sample.yml

will output

a: frog

Two non existent keys are equal

Given a sample.yml file of:

a: frog

then

yq 'select(.b == .c)' sample.yml

will output

a: frog
here
here
here