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
Create, Collect into Object
This is used to construct objects (or maps). This can be used against existing yaml, or to create fresh yaml documents.
Note that versions prior to 4.18 require the 'eval/e' command to be specified.
yq e <exp> <file>
Collect empty object
Running
1
yq --null-input
'{}'
Copied!
will output
1
{}
Copied!
Wrap (prefix) existing object
Given a sample.yml file of:
1
name
:
Mike
Copied!
then
1
yq
'{"wrap": .}'
sample.yml
Copied!
will output
1
wrap
:
2
name
:
Mike
Copied!
Using splat to create multiple objects
Given a sample.yml file of:
1
name
:
Mike
2
pets
:
3
-
cat
4
-
dog
Copied!
then
1
yq
'{.name: .pets.[]}'
sample.yml
Copied!
will output
1
Mike
:
cat
2
Mike
:
dog
Copied!
Working with multiple documents
Given a sample.yml file of:
1
name
:
Mike
2
pets
:
3
-
cat
4
-
dog
5
---
6
name
:
Rosey
7
pets
:
8
-
monkey
9
-
sheep
Copied!
then
1
yq
'{.name: .pets.[]}'
sample.yml
Copied!
will output
1
Mike
:
cat
2
Mike
:
dog
3
Rosey
:
monkey
4
Rosey
:
sheep
Copied!
Creating yaml from scratch
Running
1
yq --null-input
'{"wrap": "frog"}'
Copied!
will output
1
wrap
:
frog
Copied!
Creating yaml from scratch with multiple objects
Running
1
yq --null-input
'(.a.b = "foo") | (.d.e = "bar")'
Copied!
will output
1
a
:
2
b
:
foo
3
d
:
4
e
:
bar
Copied!
Previous
Contains
Next
Date Time
Last modified
1mo ago
Copy link
Contents
Collect empty object
Wrap (prefix) existing object
Using splat to create multiple objects
Working with multiple documents
Creating yaml from scratch
Creating yaml from scratch with multiple objects