Skip to content

Commit

Permalink
Added multiple object example from PR #1226
Browse files Browse the repository at this point in the history
  • Loading branch information
mikefarah committed May 27, 2022
1 parent 294da55 commit 439bcaa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/yqlib/doc/operators/create-collect-into-object.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,16 @@ will output
wrap: frog
```
## Creating yaml from scratch with multiple objects
Running
```bash
yq --null-input '(.a.b = "foo") | (.d.e = "bar")'
```
will output
```yaml
a:
b: foo
d:
e: bar
```
7 changes: 7 additions & 0 deletions pkg/yqlib/operator_collect_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ var collectObjectOperatorScenarios = []expressionScenario{
"D0, P[], (!!map)::{wrap: {further: {name: Mike}}}\n",
},
},
{
description: "Creating yaml from scratch with multiple objects",
expression: `(.a.b = "foo") | (.d.e = "bar")`,
expected: []string{
"D0, P[], ()::a:\n b: foo\nd:\n e: bar\n",
},
},
}

func TestCollectObjectOperatorScenarios(t *testing.T) {
Expand Down

0 comments on commit 439bcaa

Please sign in to comment.