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-rwVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to parse a JSONPath expression, find matching values within a JSON object, and programmatically build expressions.
Migrate to `jsonpath-ng` for new projects or when upgrading Python versions. `pip install jsonpath-ng` and import `from jsonpath_ng import parse`.
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.
Avoid running Python with optimization flags that strip docstrings when using `jsonpath-rw`. Ensure `PYTHONOPTIMIZE` is not set to `2` or similar values.
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.
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 ```
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`.
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.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.