mirror of
https://github.com/mikefarah/yq.git
synced 2025-02-10 18:48:36 +00:00
1.0 KiB
1.0 KiB
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
yq eval --null-input '{}'
will output
{}
Wrap (prefix) existing object
Given a sample.yml file of:
name: Mike
'': null
then
yq eval '{"wrap": .}' sample.yml
will output
wrap:
name: Mike
'': null
Using splat to create multiple objects
Given a sample.yml file of:
name: Mike
pets: [cat, dog]
'': null
then
yq eval '{.name: .pets.[]}' sample.yml
will output
Mike: cat
Mike: dog
Working with multiple documents
Given a sample.yml file of:
name: Mike
pets: [cat, dog]
'': null
---
name: Rosey
pets: [monkey, sheep]
'': null
then
yq eval '{.name: .pets.[]}' sample.yml
will output
Mike: cat
Mike: dog
Rosey: monkey
Rosey: sheep
Creating yaml from scratch
Running
yq eval --null-input '{"wrap": "frog"}'
will output
wrap: frog