Extensions for JSONPath RW
jsonpath-rw-ext extends json-path-rw capabilities by adding multiple extensions. 'len' that allows one to get the length of a list. 'sorted' that returns a sorted version of a list, 'arithmetic' that permits one to make math operation between elements and 'filter' to select only certain elements of a list.
Each extensions will be proposed upstream and will stay here only if they are refused.
- Free software: Apache license
- Documentation: https://python-jsonpath-rw-ext.readthedocs.org/en/latest/
- Source: http://github.com/sileht/python-jsonpath-rw-ext
Quick Start
At the command line:
$ pip install jsonpath-rw-ext
Or, if you have virtualenvwrapper installed:
$ mkvirtualenv jsonpath-rw-ext $ pip install jsonpath-rw-ext
To replace the jsonpath_rw parser by this one with:
import jsonpath_rw_ext
jsonpath_rw_ext.parse("$.foo").find(...)
Or:
from jsonpath_rw_ext import parser
parser.ExtentedJsonPathParser().parse("$.foo").find(...)
Shortcut functions for getting only the matched values:
import jsonpath_rw_ext as jp
print jp.match('$.cow[*]', {'cow': ['foo', 'bar'], 'fish': 'foobar'})
# prints ['foo', 'bar']
print jp.match1('$.cow[*]', {'cow': ['foo', 'bar'], 'fish': 'foobar'})
# prints 'foo'
The jsonpath classes are not part of the public API, because the name/structure can change when they will be implemented upstream. Only the syntax shouldn't change.
Extensions
| name | Example |
|---|---|
| len |
|
| sub |
|
| split |
|
| sorted |
|
| filter |
|
| arithmetic (-+*/) |
|