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/
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 (-+*/) |
|
About arithmetic and string
Operations are done with python operators and allows types that python allows, and return [] if the operation can be done due to incompatible types.
When operators are used, a jsonpath must be be fully defined otherwise jsonpath-rw-ext can’t known if the expression is a string or a jsonpath field, in this case it will choice string as type.
Example with data:
{
'cow': 'foo',
'fish': 'bar'
}
About arithmetic and list
Arithmetic can be used against two lists if they have the same size.
Example with data:
{'objects': [
{'cow': 2, 'cat': 3},
{'cow': 4, 'cat': 6}
]}
Release files for jsonpath-rw-ext 1.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| jsonpath-rw-ext-1.2.2.tar.gz | 20.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| jsonpath_rw_ext-1.2.2-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 39.8 kB
Release files / jsonpath-rw-ext-1.2.2.tar.gz
| Download URL | jsonpath-rw-ext-1.2.2.tar.gz |
|---|---|
| Size | 20.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a9e44e803b6d87d135b09d1e5af0db4d4cf97ba62711a80aa51c8c721980a994
|
|
BLAKE2b-256 checksum How to use checksums |
d5f05d865b2543be45e3ab7a8c2ae8dfa5c3e56cfdd48f19d4455eb02f370386
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
|
Release files / jsonpath_rw_ext-1.2.2-py2.py3-none-any.whl
| Download URL | jsonpath_rw_ext-1.2.2-py2.py3-none-any.whl |
|---|---|
| Size | 19.2 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
0947e018c4e6d46f9d04c56487793c702eb225fa252891aa4ed41a9ca26f3d84
|
|
BLAKE2b-256 checksum How to use checksums |
eb69e46a4866c6afa52861bcd9bf8909a4b76fd7ac68b227b2d5673f109f0aa3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
|