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
  • Has map key
  • Select, checking for existence of deep paths
  • Has array index

Was this helpful?

  1. Operators

Has

This operation returns true if the key exists in a map (or index in an array), false otherwise.

Has map key

Given a sample.yml file of:

- a: yes
- a: ~
- a:
- b: nope

then

yq '.[] | has("a")' sample.yml

will output

true
true
true
false

Select, checking for existence of deep paths

Simply pipe in parent expressions into has

Given a sample.yml file of:

- a:
    b:
      c: cat
- a:
    b:
      d: dog

then

yq '.[] | select(.a.b | has("c"))' sample.yml

will output

a:
  b:
    c: cat

Has array index

Given a sample.yml file of:

- []
- [1]
- [1, 2]
- [1, null]
- [1, 2, 3]

then

yq '.[] | has(1)' sample.yml

will output

false
false
true
true
true
PreviousGroup ByNextKeys

Last updated 2 years ago

Was this helpful?