A light weight json path utility for Python
Project description
jsonpath-lite
A very light weight utility which parses and uses JSONPath expressions for simple interactions with the Python data structures representing a JSON document.
Usage
Say you have this JSON:
{
"Things": [
{
"Name": "Thing1",
"Value": "Dog"
}
]
}
If you want to get the value of a Thing Named Thing1:
get_json_item(JSON Document, '$.Things[?Name="Thing1"].Value')
If you want to update the value of the Thing Named Thing1 to Cat:
update_json_element(JSON Document, '$.Things[?Name="Thing1"].Value', 'Cat')
If you want to add a new Thing:
write_new_json_element(JSON Document, '$.Things', {"Name": "Thing2", "Value": "Manbearpig"})
The arguments are: the JSON like object, path to the location of the new item, value of the new item, name of the new item.
Note that a value is not supplied for newElementName since we are adding a new item to a list (array).
If you want to add a new field to one of the Things:
write_new_json_element(JSON Document, $.Things[?Name="Thing1"], True, "IsAGoodBoy")
Installation
With pip:
pip install JSONPath-Lite
Otherwise you can just grab the JSONPathLite package from this repo and import it in your project.
Notes
This project came to be out of a need to find and manipulate specific pieces of data within a large highly nested JSON structure. As such, it is designed to stop searching and return the first match for a given path. The functionality of returning all matches for a given path will be added at some point in the future.
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 JSONPath-Lite-0.0.4.tar.gz.
File metadata
- Download URL: JSONPath-Lite-0.0.4.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13a94986daa22c0f3fa76b2b0624a2b3d2bf6222cebf1962db6620e740c8a712
|
|
| MD5 |
62a332bb7f186ffe9c4a7508cbde7010
|
|
| BLAKE2b-256 |
af110326595ac99be13140b22b3f39938af0e9827ce9ffc1b313c21342139256
|
File details
Details for the file JSONPath_Lite-0.0.4-py3-none-any.whl.
File metadata
- Download URL: JSONPath_Lite-0.0.4-py3-none-any.whl
- Upload date:
- Size: 2.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d6663aeec0d51fad80bbcf55c8c547edb1ddeefe2b4740d282322d45502af29
|
|
| MD5 |
b57f6fe3d528a62d1eff0dcddb386a5e
|
|
| BLAKE2b-256 |
d0e29c539226655ba865395dfc19eba911196d8c71b599a7abee1c1e6faeb110
|