I have a JSON file with two arrays. I'd like to combine the arrays into a single array of objects, each of which contains an element from each of the original arrays.
JSON input looks like this:
{ "en": [ "E1", "E2", "E3", "E4" ], "fr": [ "F1", "F2", "F3", "F4" ] } Desired output:
[ { "en":"E1", "fr":"F1"}, { "en":"E2", "fr":"F2"}, { "en":"E3", "fr":"F3"}, { "en":"E4", "fr":"F4"} ] No matter what I try I can't tame jq into delivering this. The closest I have come is using the filter . | {en:.en[],fr:.fr[]} which gives me every possible pairing of the arrays as follows:
{ "en": "E1", "fr": "F1" } { "en": "E1", "fr": "F2" } { "en": "E1", "fr": "F3" } { "en": "E1", "fr": "F4" } { "en": "E2", "fr": "F1" } { "en": "E2", "fr": "F2" } { "en": "E2", "fr": "F3" } { "en": "E2", "fr": "F4" } { "en": "E3", "fr": "F1" } { "en": "E3", "fr": "F2" } { "en": "E3", "fr": "F3" } { "en": "E3", "fr": "F4" } { "en": "E4", "fr": "F1" } { "en": "E4", "fr": "F2" } { "en": "E4", "fr": "F3" } { "en": "E4", "fr": "F4" } How can I get it to pair the first elements of each array, the second elements, etc.
.enand.fralways fixed? or keys name could be dynamic?