I have a file with an array of JSON:
[
{
"names": [
"name1"
],
"id": "1"
},
{
"names": [
"name1",
"name2"
],
"id": "2"
}
]
and I would like to create a new file with each JSON of previous JSON array, broken down by its field "origin", like this:
[
{
"name": "name1"
"id": "1"
},
{
"name": "name1",
"id": "2"
},
{
"name": "name2",
"id": "2"
}
]
I use jq version 1.6 in a bash script.
2
Answers
Here is one way:
Online demo
Try this: