Here is volumes.json :
{
"Volumes": [
{
"AvailabilityZone": "us-east-1a",
"Tags": [
{
"Value": "vol-rescue-system",
"Key": "Name"
}
],
"VolumeId": "vol-00112233",
},
{
"AvailabilityZone": "us-east-1a",
"Tags": [
{
"Value": "vol-rescue-swap",
"Key": "Name"
}
],
"VolumeId": "vol-00112234",
},
{
"AvailabilityZone": "us-east-1a",
"Tags": [
{
"Value": "vol-rescue-storage",
"Key": "Name"
}
],
"VolumeId": "vol-00112235",
}
]
}
I need to get both the value of VolumeId
and Tags.Value
to be used as the input to invoke another command. It is easy to get a single value from the json array, but I am not able to extract multiple value from it and pass it to another bash command.
I can get a single value using this:
cat volumes.json |jq -r '.Volumes[].VolumeId' |while read v; do another_bash_command $v; done
but I am not able to get multiple value cause this is wrong:
cat volumes.json |jq -r '.Volumes[].VolumeId, .Volumes[].Tags[].Value' |while read v w; do another_bash_command $v $w; done
as it will then loop 6 times of the outcome instead of 3.
And, how do I pass those multiple json value in the loop to a bash array so I can use the value in a better way ? Like VolumeId-> $arr[0][0]
, Tags.Value-> $arr[0][1]
, AvailabilityZone-> $arr[0][2]
...etc. I have searched through SO and the jq docs, and tried readarray
, but still not able to find out the solution :( Thanks for any help given.