The JSON like this:
[
{
"id": 1,
"names": [
"apple",
"google"
]
},
{
"id": 2,
"names": [
"iphone",
"ipad",
"macbook"
]
}
]
expected output in tsv
1 apple
1 google
2 iphone
2 ipad
2 macbook
CodePudding user response:
You can use map
along with raw-output option such as
jq -r 'map( "\(.id) " .names[] )[]'
or formatting as tsv :
map( "\(.id) " .names[] ) | @tsv