I'm trying to write a bash function that would parse a json response and assert if an array of objects all satisfy some condition, but I'm getting nowhere with testing that state.
Exemplary JSON after initial transformations:
[
{
"key": "Org1",
"value": true
},
{
"key": "Org2",
"value": false
}
]
The condition is to have all elements (no matter the length of the array) to have value == true.
I'm doing the JSON transformations using jq, but I have no idea how to either store the result in a bash var so I could loop throw the elements or reduce the array to a single value that I could parse directly in an if statement.
Could anyone help?
echo "$json" | jq 'all(.value)'tests the value property of each object in the array are true.