JSONPath for Python
jsonpath-python is a lightweight and powerful implementation of the JSONPath specification for Python, enabling users to extract data from JSON objects using XPath-like expressions. It is actively maintained, with version 1.1.5 being the current release, and follows a moderate release cadence addressing fixes, performance, and security.
Warnings
- breaking A critical security fix in version 1.1.5 (released 2026-03-17) prevents Remote Code Execution (RCE) via `eval()` in filter expressions. Prior versions (<=1.1.4) were vulnerable if untrusted JSONPath expressions containing filter clauses were processed. Update immediately to prevent potential security breaches.
- breaking As of version 1.1.0, sorting arrays with mixed data types (e.g., numbers and strings) in filter expressions will now raise a `JSONPathTypeError`. Previously, this behavior was undefined and could lead to inconsistent or erroneous results without explicit error notification.
Install
-
pip install jsonpath-python
Imports
- JSONPath
from jsonpath import JSONPath
Quickstart
from jsonpath import JSONPath
data = {
"store": {
"book": [
{"category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95},
{"category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99}
],
"bicycle": {"color": "red", "price": 19.95}
}
}
# Find all authors of books
path_expression = '$..book[*].author'
path = JSONPath(path_expression)
authors = path.parse(data)
print(f"Authors: {authors}")
# Find all prices
all_prices = JSONPath('$..price').parse(data)
print(f"All prices: {all_prices}")