這裏是我的輸入JSON:JQ:ID而不是數字的輸出值
{
"channels": [
{ "id": 1, "name": "Pop"},
{ "id": 2, "name": "Rock"}
],
"links": [
{ "id": 2, "streams": [ {"url": "http://example.com/rock"} ] },
{ "id": 1, "streams": [ {"url": "http://example.com/pop"} ] }
]
}
這是我想作爲輸出:
"http://example.com/pop"
"Pop"
"http://example.com/rock"
"Rock"
所以我需要JQ基於與.links[].streams[0].url
更換.channels[].id
.links[].id
我不知道它是否正確,但這是我如何設法輸出的網址:
(.channels[].id | tostring) as $ids | [.links[]] | map({(.id | tostring): .streams[0].url}) | add as $urls | $urls[$ids]
"http://example.com/pop"
"http://example.com/rock"
問題是,我該如何將.channels[].name
添加到它?