y
y
yq
Search…
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.

Collect empty object

Running
1
yq eval --null-input '{}'
Copied!
will output
1
{}
Copied!

Wrap (prefix) existing object

Given a sample.yml file of:
1
name: Mike
Copied!
then
1
yq eval '{"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 eval '{.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 eval '{.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 eval --null-input '{"wrap": "frog"}'
Copied!
will output
1
wrap: frog
Copied!