Reputation: 3852
I would like to parse data from a JSON-file into a tsv-file, but I cannot make it work.
{
"images": [
{
"id": "592a77a5-614e-4ed8-b846-d4db1f27edbf",
"name": "ubuntu",
"tags": [
"latest"
]
},
{
"id": "592da7a5-614e-4ed8-b846-d4db1f27edbf",
"name": "debian",
"tags": [
"latest",
"10.0"
]
}
]
}
The desired output is a tab-separated table
ubuntu latest
debian latest
debian 10.0
# My data
echo '{"images":[{"id":"592a77a5-614e-4ed8-b846-d4db1f27edbf","name":"ubuntu","tags":["latest"]},{"id":"592da7a5-614e-4ed8-b846-d4db1f27edbf","name":"debian","tags":["latest","10.0"]}]}' > my.json
# My query
jq -r '.images | map({id} + (.tags | fromjson[])) | @tsv' my.json > my.tsv
First I access the images-list, then I want to make an operation over all ids, where I want the tags. I borrowed the map from a similar post, but it does not seem to work. The only difference between my query and theirs is the extra layer with the .images.
Upvotes: 0
Views: 593