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
Alternative (Default value)
This operator is used to provide alternative (or default) values when a particular expression is either null or false.
Note that versions prior to 4.18 require the 'eval/e' command to be specified.
yq e <exp> <file>
LHS is defined
Given a sample.yml file of:
1
a
:
bridge
Copied!
then
1
yq
'.a // "hello"'
sample.yml
Copied!
will output
1
bridge
Copied!
LHS is not defined
Given a sample.yml file of:
1
{}
Copied!
then
1
yq
'.a // "hello"'
sample.yml
Copied!
will output
1
hello
Copied!
LHS is null
Given a sample.yml file of:
1
a
:
~
Copied!
then
1
yq
'.a // "hello"'
sample.yml
Copied!
will output
1
hello
Copied!
LHS is false
Given a sample.yml file of:
1
a
:
false
Copied!
then
1
yq
'.a // "hello"'
sample.yml
Copied!
will output
1
hello
Copied!
RHS is an expression
Given a sample.yml file of:
1
a
:
false
2
b
:
cat
Copied!
then
1
yq
'.a // .b'
sample.yml
Copied!
will output
1
cat
Copied!
Previous
Add
Next
Anchor and Alias Operators
Last modified
4mo ago
Copy link
Contents
LHS is defined
LHS is not defined
LHS is null
LHS is false
RHS is an expression