Skip to content

Commit 439bcaa

Browse files
committed
Added multiple object example from PR #1226
1 parent 294da55 commit 439bcaa

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

pkg/yqlib/doc/operators/create-collect-into-object.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,16 @@ will output
8686
wrap: frog
8787
```
8888
89+
## Creating yaml from scratch with multiple objects
90+
Running
91+
```bash
92+
yq --null-input '(.a.b = "foo") | (.d.e = "bar")'
93+
```
94+
will output
95+
```yaml
96+
a:
97+
b: foo
98+
d:
99+
e: bar
100+
```
101+

pkg/yqlib/operator_collect_object_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ var collectObjectOperatorScenarios = []expressionScenario{
154154
"D0, P[], (!!map)::{wrap: {further: {name: Mike}}}\n",
155155
},
156156
},
157+
{
158+
description: "Creating yaml from scratch with multiple objects",
159+
expression: `(.a.b = "foo") | (.d.e = "bar")`,
160+
expected: []string{
161+
"D0, P[], ()::a:\n b: foo\nd:\n e: bar\n",
162+
},
163+
},
157164
}
158165

159166
func TestCollectObjectOperatorScenarios(t *testing.T) {

0 commit comments

Comments
 (0)