[英]how to combine a value with each of the element of another array in a JSON using jq?
The JSON like this: JSON 像这样:
[
{
"id": 1,
"names": [
"apple",
"google"
]
},
{
"id": 2,
"names": [
"iphone",
"ipad",
"macbook"
]
}
]
expected output in tsv tsv 中的预期 output
1 apple
1 google
2 iphone
2 ipad
2 macbook
You can use map
您可以使用
map
along with raw-output option such as以及原始输出选项,例如
jq -r 'map( "\(.id) " + .names[] )[]'
or formatting as tsv :或格式化为tsv :
jq -r 'map( "\(.id) " + .names[] ) | @tsv'
which outputs the result on a single line在单行上输出结果
or use或使用
jq -r 'map( "\(.id)\t" + .names[])[]'
in order to get tab-delimited results between attributes while returning each combinations on separate lines为了在属性之间获得制表符分隔的结果,同时在单独的行上返回每个组合
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.