RFC 9535 - JSONPath: Query Expressions for JSON in Python
Actively maintained. Last release 8 days ago, commits in 7 of the last 26 weeks. A safe choice.
pip install jsonpath-rfc9535RFC 9535 JSONPath: Query Expressions for JSON in Python
We follow RFC 9535 strictly and test against the JSONPath Compliance Test Suite.
Table of Contents
Install
Install Python JSONPath RFC 9535 using pip:
python -m pip install jsonpath-rfc9535
Or uv:
uv add jsonpath-rfc9535
Or Pipenv:
pipenv install -u jsonpath-rfc9535
Links
- Documentation: https://jg-rp.github.io/python-jsonpath-rfc9535/
- Change log: https://github.com/jg-rp/python-jsonpath-rfc9535/blob/main/CHANGELOG.md
- PyPi: https://pypi.org/project/jsonpath-rfc9535
- Source code: https://github.com/jg-rp/python-jsonpath-rfc9535
- Issue tracker: https://github.com/jg-rp/python-jsonpath-rfc9535/issues
Example
import jsonpath_rfc9535 as jsonpath
expr = "$.users[?@.status == 'pending'].name"
data: dict[str, object] = {
"users": [
{"id": "usr_101", "name": "Alice", "status": "pending"},
{"id": "usr_102", "name": "Bob", "status": "active"},
{"id": "usr_103", "name": "Charlie", "status": "pending"},
],
}
nodes = jsonpath.find(expr, data)
print(nodes.values()) # ['Alice', 'Charlie']
print(nodes.locations()) # [('users', 0, 'name'), ('users', 2, 'name')]
print(nodes.paths()) # ["$['users'][0]['name']", "$['users'][2]['name']"]
Related projects
- Python JSONPath - Another Python package implementing JSONPath, but with additional features and customization options.
- JSON P3 - RFC 9535 implemented in TypeScript.
License
python-jsonpath-rfc9535 is distributed under the terms of the MIT license.