I have converted the following JSON from jq to CSV.
{
"items": [
{
"id": "1",
"name": "masao",
"images": ["001.jpg", "002.jpg" ]
},
{
"id": "2",
"name": "video",
"images": ["003.jpg", "004.jpg" ]
}
]
}
I create a CSV using the command below, but I don't know how to get information about images nested in an array.
cat sample.json | jq-r'.items [ ] | [ .id, .name ] | @csv' | sed-e's /"//g';
1,masao
2, video
What commands should I enter?
1,masao,001.jpg
2,video,003.jpg
Is it possible to retrieve it like this?
I was told in the comments.
cat sample.json | jq-r'.items[] | [.id, .name, images[0]] | @csv' | sed-e's /" //g';
Also, without using sed-e's /"//g';
cat sample.json|jq-r'.items[]|"\(.id), \(.name), \(.images[0])"'
If you write that, you can remove the double quotation.It was very helpful.
© 2024 OneMinuteCode. All rights reserved.