You can use the map()
function to create an array of boolean values indicating which of the nested objects had a property status
with the value true
(or any other value):
crictl ... | jq -r '.status|.conditions|map(.status==true)'
Output:
[
true,
true
]
Use the all
function to check if all values in this result array are true (if you want to check if at least one result is true use the any
function instead).
crictl ... | jq -r '.status|.conditions|map(.status==true)|all'
That will create the output true
or false
, depending on whether or not all of the values in the array were true. Run jq
with the additional parameter -e
to have the program exit with 0 or 1 for a result true
or false
respectively.
crictl ... | jq -re '.status|.conditions|map(.status==true)|all'
An alternative to the above would be to get the values of the status
fields as an array, and then pass that array to the all
function:
crictl ... | jq -re '[.status|.conditions[]|.status]|all'
However, that will only work if the values of the fields already are booleans. It will not work if the values have a different type and you need to check for a particular value (e.g. the string "foo"). The first approach is more generic.