python-jsonpath: JSONPath, JSON Pointer and JSON Patch for Python. · Pythie
Python JSONPath
A flexible JSONPath engine for Python.
We follow RFC 9535 and test against the JSONPath Compliance Test Suite .
Table of Contents
Install
Install Python JSONPath using pip :
pip install python-jsonpath
Or Pipenv :
pipenv install -u python-jsonpath
Or from conda-forge :
conda install -c conda-forge python-jsonpath
Links
Related projects
JSONPath RFC 9535 - A minimal, slightly cleaner Python implementation of RFC 9535. If you're not interested JSONPath sytax beyond that defined in RFC 9535, you might choose jsonpath-rfc9535 over python-jsonpath .
jsonpath-rfc9535 also includes utilities for verifying and testing the JSONPath Compliance Test Suite . Most notably the nondeterministic behavior of some JSONPath selectors.
JSON P3 - RFC 9535 implemented in TypeScript. JSON P3 does not include all the non-standard features of Python JSONPath, but does define some optional extra syntax .
Ruby JSON P3 - RFC 9535, RFC 6901 and RFC 6902 implemented in Ruby.
Examples
JSONPath import jsonpath
data = {
"users": [
{"name": "Sue", "score": 100},
{"name": "John", "score": 86},
{"name": "Sally", "score": 84},
{"name": "Jane", "score": 55},
]
}
user_names = jsonpath.findall("$.users[?@.score < 100].name", data)
print(user_names) # ['John', 'Sally', 'Jane']
JSON Pointer from jsonpath import pointer
data = {
"users": [
{"name": "Sue", "score": 100},
{"name": "John", "score": 86},
{"name": "Sally", "score": 84},
{"name": "Jane", "score": 55},
]
}
sue_score = pointer.resolve("/users/0/score", data)
print(sue_score) # 100
jane_score = pointer.resolve(["users", 3, "score"], data)
print(jane_score) # 55
JSON Patch
[!WARNING]
Objects passed to patch.apply() and JSONPatch.apply() are modified in place, even if a patch operation fails. Use patch.atomic() or JSONPatch.atomic() if you need to preserve input data on patch failure.
from jsonpath import patch
patch_operations = [
{"op": "add", "path": "/some/foo", "value": {"foo": {}}},
{"op": "add", "path": "/some/foo", "value": {"bar": []}},
{"op": "copy", "from": "/some/other", "path": "/some/foo/else"},
{"op": "add", "path": "/some/foo/bar/-", "value": 1},
]
data = {"some": {"other": "thing"}}
patch.apply(patch_operations, data)
print(data) # {'some': {'other': 'thing', 'foo': {'bar': [1], 'else': 'thing'}}}
Use patch.atomic() or JSONPatch.atomic() if you need to preserve input data on patch failure.
import contextlib
from jsonpath import JSONPatchError
from jsonpath import patch
patch_operations = [
{"op": "add", "path": "/some/foo", "value": {"foo": {}}},
{"op": "add", "path": "/some/foo", "value": {"bar": []}},
{"op": "copy", "from": "/some/other", "path": "/some/foo/else"},
{"op": "add", "path": "/some/foo/bar/-", "value": 1},
{"op": "test", "path": "/some/thing", "value": "baz"}, # Always fails
]
data = {"some": {"other": "thing"}}
with contextlib.suppress(JSONPatchError):
patch.atomic(patch_operations, data)
assert data == {"some": {"other": "thing"}}
patch.patched(ops, data) and JSONPatch.patched(data) apply patch operations to a deep copy of data.
from jsonpath import patch
patch_operations = [
{"op": "add", "path": "/some/foo", "value": {"foo": {}}},
{"op": "add", "path": "/some/foo", "value": {"bar": []}},
{"op": "copy", "from": "/some/other", "path": "/some/foo/else"},
{"op": "add", "path": "/some/foo/bar/-", "value": 1},
]
data = {"some": {"other": "thing"}}
patched_data = patch.patched(patch_operations, data)
assert data != patched_data
License python-jsonpath is distributed under the terms of the MIT license.
Popularity
Downloads, last 7 days 588.4K-9%
Stars, last 7 days –
Direct dependents 35
All dependents 93 77
Healthy
Maintenance, out of 100
Recent release
last release 6 days ago
Commit activity
9/26 weeks with commits
Release cadence
6 releases in 12 months
Issues & PRs handled
86% closed in the past year
Contributor spread
6 authors in last 100 commits
OpenSSF Scorecard
not evaluated
Releases
Latest 2.3.0
Released Nov 22, 2026
Releases, 12 months 6
First release Mar 28, 2023 Compatibility
Requires Python >=3.8
Tested on 3.8 · 3.9 · 3.10 · 3.11 · 3.12 · 3.13 · 3.14 · 3.15
License MIT (Permissive) AlternativesUse instead of python-jsonpath: tools that do the same job, closest first.
Compare with jsonpath-python → Compare with jsonpath-ng → Compare with jsonpath-rfc9535 → Compare all 4 →
A lightweight and powerful JSONPath implementation for Python
A final implementation of JSONPath for Python that aims to be standard compliant, including arithmetic and binary comparison operators and providing clear AST for metaprogramming.
RFC 9535 - JSONPath: Query Expressions for JSON in Python
Utilities & Language Tools 13 1.1M/moReleased Nov 22, 2026 A final implementation of JSONPath for Python that aims to be standard compliant, including arithmetic and binary comparison operators and providing clear AST for metaprogramming.
A robust and significantly extended implementation of JSONPath for Python, with a clear AST for metaprogramming.
Identify specific nodes in a JSON document (RFC 6901)