Using the Python jmespath
library, how can I distinguish “matched the expression, the value is None
” versus “failed to match the expression”?
The jmespath.search
function returns None
in two distinct cases:
>>> import jmespath
>>> foo = {'bar': {'lorem': 13, 'ipsum': None}}
>>> repr(jmespath.search('bar.lorem', foo))
'13'
>>> repr(jmespath.search('bar.ipsum', foo)) # Path matches, value None
'None'
>>> repr(jmespath.search('dolor', foo)) # Path does not match
'None'
It appears the JMESPath search API returns None
in these two distinct cases. How can the caller know the difference between them?