Get values from JSON objects using a path expression
Project description
Get values from JSON objects usings a path expression. Optional type checking is possible.
>>> from jsonget import json_get
>>> j = {
... "foo": {"num": 3.4, "s": "Text"},
... "arr": [10, 20, 30],
... }
>>> json_get(j, "/foo/num")
3.4
>>> json_get(j, "/arr[1]")
20
>>> json_get(j, "/foo/unknown")
Traceback (most recent call last):
...
ValueError: JSON path '/foo/unknown' not found
Values are optionally checked against one of the following types: str, int, float, bool, list, and dict. Checking for null values is not supported.
>>> json_get(j, "/foo/num", str)
Traceback (most recent call last):
...
TypeError: wrong JSON type str != float
float will match any number, int will only match numbers without a fractional part.
>>> json_get(j, "/foo/num", float)
3.4
>>> json_get(j, "/foo/num", int)
Traceback (most recent call last):
...
TypeError: wrong JSON type int != float
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
json-get-1.0.tar.gz
(3.3 kB
view details)
File details
Details for the file json-get-1.0.tar.gz.
File metadata
- Download URL: json-get-1.0.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3512b625808233eee3cf1b5fa10500f03719ff844d656bdec240c22c24c07d84
|
|
| MD5 |
01dd2bdfbca5246dcc7a5002853a30ad
|
|
| BLAKE2b-256 |
d3265c92568634f2f639679f9b12ce81eff0f7216b5b02c1faad6ddb7ab5d03c
|