Registry / serialization / jsonpath-rw

jsonpath-rw

JSON →
library1.4.0pypypi✓ verified 24d ago

JSONPath-RW (jsonpath-rw) is a Python library that provides a robust and extended implementation of JSONPath, featuring a clear Abstract Syntax Tree (AST) for metaprogramming. As of its last release (1.4.0 in April 2015), it was primarily tested with Python 2.7, 3.4, 3.5, 3.6, and 3.7. While functional, its development is inactive, and more actively maintained and feature-rich alternatives like `jsonpath-ng` are now available, which merge its capabilities with `jsonpath-rw-ext` for modern Python versions.

pip install jsonpath-rw
INSTALL
IMPORT
SIG · JSONPATH-RW
J
jsonpath-rw
serializationpythonv1.4.0
Install
2.6s avg
Import
57ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.060s · 19.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.6s · import 0.054s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse
from jsonpath_rw import parse
from jsonpath_rw.jsonpath import parse
The 'parse' function is directly exposed at the top-level `jsonpath_rw` package.
jsonpath
from jsonpath_rw import jsonpath
from jsonpath_rw.jsonpath import jsonpath
The 'jsonpath' module (containing various expression types) is exposed at the top-level `jsonpath_rw` package.

This quickstart demonstrates how to parse a JSONPath expression, find matching values within a JSON object, and programmatically build expressions.

from jsonpath_rw import jsonpath, parse # Example JSON data data = {'foo': [{'baz': 1}, {'baz': 2}, {'qux': 3}]} # Parse a JSONPath expression jsonpath_expr = parse('foo[*].baz') # Find matches in the data matches = [match.value for match in jsonpath_expr.find(data)] print(f"Extracted values: {matches}") # Access full path of matches full_paths = [str(match.full_path) for match in jsonpath_expr.find(data)] print(f"Full paths of matches: {full_paths}") # Programmatic expression building from jsonpath_rw.jsonpath import Fields, Slice, Child jsonpath_expr_direct = Fields('foo').child(Slice('*')).child(Fields('baz')) matches_direct = [match.value for match in jsonpath_expr_direct.find(data)] print(f"Extracted values (programmatic): {matches_direct}")
Debug
Known issues
deprecatedThe `jsonpath-rw` library is no longer actively maintained. For modern Python applications (3.8+), consider using `jsonpath-ng` (jsonpath-ng.readthedocs.io), which merges the features of `jsonpath-rw` and `jsonpath-rw-ext` and offers active development and broader Python version support.
fix
Migrate to `jsonpath-ng` for new projects or when upgrading Python versions. `pip install jsonpath-ng` and import `from jsonpath_ng import parse`.
affects: 1.4.0 and earlier
gotchaFiltering expressions (e.g., `[?()]`) are not directly supported by `jsonpath-rw`'s default parser. Attempting to use them will result in a `ParseError`. These extensions are available through the companion library `jsonpath-rw-ext`.
fix
If filtering is required, install `jsonpath-rw-ext` (`pip install jsonpath-rw-ext`) and use its extended parser: `from jsonpath_rw_ext import parse`. Alternatively, switch to `jsonpath-ng` which includes these extensions by default.
affects: All versions
gotchaThe underlying parsing toolkit, PLY, does not work when Python docstrings are removed (e.g., by running Python with `PYTHONOPTIMIZE=2` or `python -OO`). This can lead to unexpected failures.
fix
Avoid running Python with optimization flags that strip docstrings when using `jsonpath-rw`. Ensure `PYTHONOPTIMIZE` is not set to `2` or similar values.
affects: All versions
gotchaThe `jsonpath-rw` library, as of version 1.4.0, was primarily tested with Python versions up to 3.7. While it might function on newer Python versions, active development and testing for compatibility beyond 3.7 is not ongoing. There have been reports of build failures with newer `setuptools` versions.
fix
For Python 3.8 and newer, it is strongly recommended to use `jsonpath-ng` (which explicitly supports CPython 3.10 and higher) to ensure compatibility and receive ongoing updates.
affects: 1.4.0 and earlier, particularly with Python 3.8+ or recent `setuptools`.
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'jsonpath-rw'
The `jsonpath-rw` package is not installed in your Python environment, or there's a typo in the import statement.
fix
Ensure the package is installed using pip. The correct package name for installation is `jsonpath-rw`, but the import statement uses `jsonpath_rw`. 
```bash
pip install jsonpath-rw
```
Then import using:
```python
from jsonpath_rw import jsonpath, parse
```
ImportError: No module named jsonpath_rw
This error is typically seen in older Python environments or when the package is not installed correctly. It's the `ModuleNotFoundError` equivalent for `import` statements.
fix
Install the package using pip. 
```bash
pip install jsonpath-rw
```
If already installed, verify your Python environment's paths or consider using a virtual environment. The import statement should be `from jsonpath_rw import jsonpath, parse`.
jsonpath_rw.lexer.JsonPathLexerError: Error on line X, col Y: Unexpected character: ?
The `jsonpath-rw` library, particularly version 1.4.0, has limited or no native support for advanced filter expressions using `?` as specified in some JSONPath standards. Users often encounter this when trying to use filter conditions that are not recognized by `jsonpath-rw`'s parser.
fix
For advanced filter expressions, use `jsonpath-rw-ext` or the more modern and actively maintained `jsonpath-ng` library, which provides extended JSONPath capabilities and merges `jsonpath-rw` and `jsonpath-rw-ext`.
```bash
pip install jsonpath-ng
```
Then, for `jsonpath-ng`:
```python
from jsonpath_ng import jsonpath, parse
# Or for extended features
from jsonpath_ng.ext import parse

jsonpath_expr = parse('$.items[?(@.name = "example")]')
```
If you must use `jsonpath-rw`, simplify your JSONPath expression to avoid advanced filters.
AttributeError: module 'jsonpath' has no attribute 'jsonpath'
This error usually occurs when a user incorrectly imports a module named `jsonpath` (which might be a different, less commonly used library, or even a local file) and expects it to have the `jsonpath` attribute from `jsonpath-rw`'s API, or when they try to call `jsonpath.jsonpath()` directly instead of using the `parse` function from `jsonpath_rw`.
fix
Ensure you are importing from the correct library and using its API. The `jsonpath-rw` library exposes its core functionality, including the `parse` function, directly from the `jsonpath_rw` module.
```python
from jsonpath_rw import jsonpath, parse

# To parse an expression:
jsonpath_expr = parse('your.json.path')

# To find matches:
matches = jsonpath_expr.find(your_data)
```
If you intended to use a different `jsonpath` library, ensure it's installed and imported correctly according to its documentation.
Upgrade
Version history
1.4.0latest on PyPI · released Apr 19, 2015
Audit
Dependencies
plyrequiredRequired for parsing JSONPath expressions.
decoratorrequiredGeneral utility.
sixrequiredPython 2/3 compatibility layer.
Agent activity
5 hits · last 30 days
node
4
Resources
jsonpath-rw — pip install jsonpath-rw · libregistry