diff --git a/pkg/yqlib/doc/operators/create-collect-into-object.md b/pkg/yqlib/doc/operators/create-collect-into-object.md index b90866c9..12802ba5 100644 --- a/pkg/yqlib/doc/operators/create-collect-into-object.md +++ b/pkg/yqlib/doc/operators/create-collect-into-object.md @@ -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 +``` + diff --git a/pkg/yqlib/operator_collect_object_test.go b/pkg/yqlib/operator_collect_object_test.go index 6c1cf743..eda96ad4 100644 --- a/pkg/yqlib/operator_collect_object_test.go +++ b/pkg/yqlib/operator_collect_object_test.go @@ -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) {