JMESPath - How to check if key's value is contained in JSON object and return the value if true?

Viewed 10

I have a contact JSON object like this:

{ "contactType": "Manager", "firstName": "Tom", "lastName": "Jones" }

I am trying to query the object like:

(contactType=='Manager')

to check if the contactType is indeed Manager. My question is if the expression is true, how can I return the value, something like firstName, from the confirmed Manager object? I know this is easily done with arrays by piping, such as if I had multiple contacts and used:

([?contactType=='Manager']|[0].firstName) 

but how can I achieve the same result checking a singular JSON in a single expression?

0 Answers
Related