Skip to main content
https://travis-ci.org/sileht/python-jsonpath-rw-ext.png?branch=master Latest Version Downloads

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.

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(...)

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

  • $.objects.`len`

sub

  • $.field.`sub(/foo\\+(.*)/, \\1)`

split

  • $.field.`split(+, 2, -1)`

  • $.field.`split(sep, segement, maxsplit)`

sorted

  • $.objects.`sorted`

  • $.objects[\some_field]

  • $.objects[\some_field,/other_field]

filter

  • $.objects[?(@some_field > 5)]

  • $.objects[?some_field = “foobar”)]

  • $.objects[?some_field > 5 & other < 2)]

arithmetic (-+*/)

  • $.foo + “_” + $.bar

  • $.foo * 12

  • $.objects[*].cow + $.objects[*].cat

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'
}
cow + fish returns cowfish
$.cow + $.fish returns foobar
$.cow + “_” + $.fish returns foo_bar
$.cow + “_” + fish returns foo_fish

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}
]}
$.objects[*].cow + $.objects[*].cat returns [6, 9]

Metadata

Release files for jsonpath-rw-ext 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jsonpath-rw-ext 1.0.0
File Size Uploaded Provenance Actions
jsonpath-rw-ext-1.0.0.tar.gz 19.6 kB Without provenance Details for jsonpath-rw-ext-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for jsonpath-rw-ext 1.0.0
File Interpreter ABI Platform Actions
jsonpath_rw_ext-1.0.0-py2.py3-none-any.whl Python 2, Python 3 none any Details for jsonpath_rw_ext-1.0.0-py2.py3-none-any.whl

Total release size: 36.4 kB

Release files / jsonpath-rw-ext-1.0.0.tar.gz

Download URL jsonpath-rw-ext-1.0.0.tar.gz
Size 19.6 kB
Tags Source
SHA-256 checksum
How to use checksums
43f8a8324b4cf8af7d93581f217424d3ffc89bfeaf8a3594ccdf45ea4d2d5dd2
BLAKE2b-256 checksum
How to use checksums
b3d811a3d276506244d95779b3ac64f1b531f4b4ab3508f261aa639a7db8feeb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / jsonpath_rw_ext-1.0.0-py2.py3-none-any.whl

Download URL jsonpath_rw_ext-1.0.0-py2.py3-none-any.whl
Size 16.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
88c7719e8a2090aa70afba41bdfb656f57afb3d1130f8d26ef1911961b740475
BLAKE2b-256 checksum
How to use checksums
4a6c6c229e01fd864d640e540c94d07dec9a34328f98087b65d2a44ba342d5a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for jsonpath-rw-ext 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page