y
y
yq
Search…
y
y
yq
v4.x
yq
How It Works
Upgrading from V3
Commands
Evaluate
Evaluate All
Shell Completion
Operators
Add
Alternative (Default value)
Anchor and Alias Operators
Assign (Update)
Boolean Operators
Collect into Array
Column
Comment Operators
Compare Operators
Contains
Create, Collect into Object
Date Time
Delete
Document Index
Encode / Decode
Entries
Env Variable Operators
Equals
Eval
File Operators
Flatten
Group By
Has
Keys
Length
Line
Load
Map
Multiply (Merge)
Parent
Path
Pick
Pipe
Recursive Descent (Glob)
Reduce
Reverse
Select
Sort
Sort Keys
Split into Documents
String Operators
Style
Subtract
Tag
Traverse (Read)
Union
Unique
Variable Operators
With
Usage
Output format
Working with CSV, TSV
Working with JSON
Working with Properties
Working with XML
Front Matter
Split into multiple files
GitHub Action
Tips, Tricks, Troubleshooting
Github Page
Powered By
GitBook
Has
This is operation that returns true if the key exists in a map (or index in an array), false otherwise.
Note that versions prior to 4.18 require the 'eval/e' command to be specified.
yq e <exp> <file>
Has map key
Given a sample.yml file of:
1
-
a
:
yes
2
-
a
:
~
3
-
a
:
4
-
b
:
nope
Copied!
then
1
yq
'.[] | has("a")'
sample.yml
Copied!
will output
1
true
2
true
3
true
4
false
Copied!
Select, checking for existence of deep paths
Simply pipe in parent expressions into
has
Given a sample.yml file of:
1
-
a
:
2
b
:
3
c
:
cat
4
-
a
:
5
b
:
6
d
:
dog
Copied!
then
1
yq
'.[] | select(.a.b | has("c"))'
sample.yml
Copied!
will output
1
a
:
2
b
:
3
c
:
cat
Copied!
Has array index
Given a sample.yml file of:
1
-
[]
2
-
[
1
]
3
-
[
1
,
2
]
4
-
[
1
,
null
]
5
-
[
1
,
2
,
3
]
Copied!
then
1
yq
'.[] | has(1)'
sample.yml
Copied!
will output
1
false
2
false
3
true
4
true
5
true
Copied!
Previous
Group By
Next
Keys
Last modified
4mo ago
Copy link
Contents
Has map key
Select, checking for existence of deep paths
Has array index