A light weight json path utility for Python
Project description
jsonpath-lite
A very light weight utility which parses and uses JSONPath expressions to do things 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")
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
Hashes for JSONPath_Lite-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3abb475221a7e8e0f87471f8ade629108cbbcb3affddadaa67b8609ae99e46c |
|
MD5 | 59d5102c2f6fd7165b132154951f8cb4 |
|
BLAKE2b-256 | 48b10b55aa0b2df75597d2b050ab5d305f5817094895362baf7d6b42515dce1d |