JSONPath, JSON Pointer and JSON Patch for Python.
Project description
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
- Documentation: https://jg-rp.github.io/python-jsonpath/.
- JSONPath Syntax: https://jg-rp.github.io/python-jsonpath/syntax/
- Change log: https://github.com/jg-rp/python-jsonpath/blob/main/CHANGELOG.md
- PyPi: https://pypi.org/project/python-jsonpath
- Source code: https://github.com/jg-rp/python-jsonpath
- Issue tracker: https://github.com/jg-rp/python-jsonpath/issues
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
We include an RFC 6901 compliant implementation of JSON Pointer. See JSON Pointer quick start, guide and API reference
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
We also include an RFC 6902 compliant implementation of JSON Patch. See JSON Patch quick start and API reference
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'}}}
License
python-jsonpath is distributed under the terms of the MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_jsonpath-2.0.2.tar.gz.
File metadata
- Download URL: python_jsonpath-2.0.2.tar.gz
- Upload date:
- Size: 49.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41abb6660b3ee54d5ae77e4b0e901049fb1662ad90de241f038df47edc75ee60
|
|
| MD5 |
17afd2814a6938cc514187e3925e127c
|
|
| BLAKE2b-256 |
8ee507f99c0fb448eeb2c9db5e817f8a9c43e3f4a7b59934adbe421a39677025
|
File details
Details for the file python_jsonpath-2.0.2-py3-none-any.whl.
File metadata
- Download URL: python_jsonpath-2.0.2-py3-none-any.whl
- Upload date:
- Size: 64.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f8ab612f815ce10c03bf0deaede87235f3381b109a60b4a22744069953627e3
|
|
| MD5 |
e0cc095b36ea642488f9d13ccd6dab07
|
|
| BLAKE2b-256 |
842cc1282c47a8bb641c3068f47780c5f1f5c97cdc39cda3ec507c64c029764e
|