Comment on page
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.
Running
yq --null-input '{}'
will output
{}
Given a sample.yml file of:
name: Mike
then
yq '{"wrap": .}' sample.yml
will output
wrap:
name: Mike
Given a sample.yml file of:
name: Mike
pets:
- cat
- dog
then
yq '{.name: .pets.[]}' sample.yml
will output
Mike: cat
Mike: dog
Given a sample.yml file of:
name: Mike
pets:
- cat
- dog
---
name: Rosey
pets:
- monkey
- sheep
then
yq '{.name: .pets.[]}' sample.yml
will output
Mike: cat
Mike: dog
---
Rosey: monkey
Rosey: sheep
Running
yq --null-input '{"wrap": "frog"}'
will output
wrap: frog
Running
yq --null-input '(.a.b = "foo") | (.d.e = "bar")'
will output
a:
b: foo
d:
e: bar
Last modified 17d ago