Like the multiple operator in jq, depending on the operands, this multiply operator will do different things. Currently only objects are supported, which have the effect of merging the RHS into the LHS.
To concatenate arrays when merging objects, use the *+ form (see examples below). This will recursively merge objects, appending arrays when it encounters them.
To merge only existing fields, use the ? form. Note that this can be used with the concatenate arrays too +?. Note that when merging objects, this operator returns the merged object (not the parent). This will be clearer in the examples below.
Multiplication of strings and numbers are not yet supported.
Note the use of eval-all
to ensure all documents are loaded into memory.
yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' file1.yaml file2.yaml
Given a sample.yml file of:
a:field: mefieldA: catb:field:g: wizzfieldB: dog
then
yq eval '.a * .b' sample.yml
will output
field:g: wizzfieldA: catfieldB: dog
Given a sample.yml file of:
a:field: mefieldA: catb:field:g: wizzfieldB: dog
then
yq eval '. * {"a":.b}' sample.yml
will output
a:field:g: wizzfieldA: catfieldB: dogb:field:g: wizzfieldB: dog
Given a sample.yml file of:
a: {things: great}b:also: "me"
then
yq eval '. * {"a":.b}' sample.yml
will output
a: {things: great, also: "me"}b:also: "me"
Given a sample.yml file of:
a:- 1- 2- 3b:- 3- 4- 5
then
yq eval '. * {"a":.b}' sample.yml
will output
a:- 3- 4- 5b:- 3- 4- 5
Given a sample.yml file of:
a:thing: onecat: frogb:missing: twothing: two
then
yq eval '.a *? .b' sample.yml
will output
thing: twocat: frog
Given a sample.yml file of:
a:array:- 1- 2- animal: dogvalue: coconutb:array:- 3- 4- animal: catvalue: banana
then
yq eval '.a *+ .b' sample.yml
will output
array:- 1- 2- animal: dog- 3- 4- animal: catvalue: banana
Given a sample.yml file of:
a:thing:- 1- 2b:thing:- 3- 4another:- 1
then
yq eval '.a *?+ .b' sample.yml
will output
thing:- 1- 2- 3- 4
Given a sample.yml file of:
a: catb: dog
then
yq eval '. * {"a": {"c": .a}}' sample.yml
will output
a:c: catb: dog
Given a sample.yml file of:
a: &catc: frogb:f: *catc:g: thongs
then
yq eval '.c * .b' sample.yml
will output
g: thongsf: *cat
Given a sample.yml file of:
a:c: &cat frogb:f: *catc:g: thongs
then
yq eval '.c * .a' sample.yml
will output
g: thongsc: &cat frog
Given a sample.yml file of:
foo: &fooa: foo_athing: foo_thingc: foo_cbar: &barb: bar_bthing: bar_thingc: bar_cfoobarList:b: foobarList_b!!merge <<:- *foo- *barc: foobarList_cfoobar:c: foobar_c!!merge <<: *foothing: foobar_thing
then
yq eval '.foobar * .foobarList' sample.yml
will output
c: foobarList_c<<:- *foo- *barthing: foobar_thingb: foobarList_b