I am trying to find a clean way to assign 2 json string values to 2 variables within a while loop. The loop and input I am working with are as follows.
INPUT:
foo='
[
{
"name":"name string (more info)",
"nested_name":{
"name":"my name",
"conclusion":"failure",
"number":11
}
},
{
"name":"name string (more info)",
"nested_name":{
"name":"my other name",
"conclusion":"failure",
"number":13
}
}
]'
Currently I have the following:
echo "$foo" | jq ".[].name,.[].nested_name.name" | while read -r foo bar; do
# do stuff with foo and bar
done
In iteration 1, I want:
foo = "name string (more info)"
bar = "my name"
Iteration 2:
foo = "name string (more info)"
bar = "my other name"
However this generates the following incorrect output:
foo = "name
bar = string (more info)"
foo = "name
bar = string (more info)"
foo = "my
bar = name"
foo = "my
bar = other name"
I've been at this all day, any input or suggestions would be very much appreciated!