Open spmp opened 6 years ago
In case anyone else sees this, it seems to work for me.
Added the custom function to a class I already had with other custom functions.
opts=jmespath.Options(custom_functions=custom.CustomFunctions())
>>> jmespath.search('issubset(`[0,1]`, `[0,1,2]`)',{}, opts)
True
>>> jmespath.search('issubset(`[0,1]`,None)',{}, opts)
False
>>> data= [{"foo":"bar"}, {'1': [1,2], '0': [1]}]
>>> jmespath.search('[].issubset("0","1")', data, opts)
[False, True]
*** remove the "null" option from the signature decoration
opts=jmespath.Options(custom_functions=custom.CustomFunctions())
>>> jmespath.search('[].issubset("0","1")', data, opts)
Traceback (most recent call last):
jmespath.exceptions.JMESPathTypeError: In function issubset(), invalid type for value: None, expected one of: ['array'], received: "null"
If its still an issue could you post your full search call? I've had issues in the past where invalid type is returned when I had a syntax issue.
HTH
I have a custom function to test array subsets, but sometimes the field does not exist in my JSON, in this case the input is
none
instead of['some', 'array']
giving the error:I tired adding
null
to the input types, but this didn't help:How can I handle this case please? Can I filter only if key exists?