Extensions for JSONPath RW
This extensions will be proposed upstream and will stay here only if they are refused.
At the command line:
$ pip install jsonpath-rw-ext
Or, if you have virtualenvwrapper installed:
$ mkvirtualenv jsonpath-rw-ext
$ pip install jsonpath-rw-ext
name | Example |
---|---|
len |
|
sorted |
|
filter |
|
arithmetic (-+*/) |
|
Operations are done with python operators and allows types that python allows, and return None if the operation can be done due to imcompatible types.
When operators are used, a jsonpath must be be fully defined otherwise if jsonpath-rw-ext can’t known if expression is a string or a jsonpath field, it will choice string.
Example with data:
{
'cow': 'foo',
'fish': 'bar'
}
Arithmetic can be used against two list if they have the same size.
Example with data:
{'objects': [
{'cow': 2, 'cat': 3},
{'cow': 4, 'cat': 6}
]}