jmespath / jmespath/jmespath.py
Custom function handling NoneType/Null/none
- Dominant language
- Python
- Stars
- 2.4k
- Forks
- 212
- PR merge metrics
- No merged PRs in 30d
Description
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:
```
JMESPathTypeError: In function issubset(), invalid type for value: None, expected one of: ['array', 'null'], received: "null"
```
I tired adding `null` to the input types, but this didn't help:
```python
class CustomFunctions(jmespath.functions.Functions):
# Check if the list x is a subset of the list y
@jmespath.functions.signature({'types': ['array', 'null']}, {'types': ['array', 'null']})
def _func_issubset(self, x, y):
if x is None or y is None:
return False
else:
return set(x).issubset(y)
```
How can I handle this case please? Can I filter only if key exists?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.