Is it possible to accomplish something like this using json_query
? I wasn't able to find anything after quite a bit of searching (neither with json_query
nor with jmespath
). Everything I was able to find assumed that the structure of the dict/json
is known (i.e. the depth of the searched-for key is known).
Sample JSON input:
{
"changed": false,
"msg": {
"Data": {
"Message": "returned status code doesn't match with the expected success code",
"Status": "Failed",
"StatusCode": 409
},
"Message": "none",
"Status": "Failed",
"StatusCode": 409,
"error": {
"error": {
"@Message.ExtendedInfo": [
{
"Message": "Server is already powered OFF.",
"MessageArgs": [
],
"MessageArgs@odata.count": 0,
"MessageId": "IDRAC.1.6.PSU502",
"RelatedProperties": [
],
"RelatedProperties@odata.count": 0,
"Resolution": "No response action is required.",
"Severity": "Informational"
}
],
"code": "Base.1.0.GeneralError",
"message": "A general error has occurred. See ExtendedInfo for more information"
}
},
"retval": true
}
}
I would like to check whether a key Message is present with the value Server is already powered OFF. without assuming the depth of the key/structure of the JSON.