Given such a json (very simplified from my real use case), which file is service-def-test.json:
{
"definition": {
"services": [{
"image": {
"name": "img1",
"tag": "2.0.1"
}
}, {
"image": {
"name": "img2",
"tag": "1.4.0"
}
}, {
"image": {
"name": "img3",
"tag": "1.2.5"
}
}
]
}
}
I would like to get twice a one-line list of values, so that I could export each line to a variable and proceed it eventually:
images=[img1, img2, img3]
tags=[2.0.1, 1.4.0, 1.2.5]
jq is probably the way to go
jq -r .definition.services[].image.name service-def-test.json
gives
img1
img2
img3
How could I transform that to one line? Could jq directly output what I want? I tried options like -c but I did not manage to have the output in one line. Other though is about used sed or awk to transform the output.
What would be your simplest solution?