Skip to main content

Get values from JSON objects using a path expression

Project description

https://img.shields.io/github/release/srittau/python-json-get/all.svg https://travis-ci.org/srittau/python-json-get.svg?branch=master

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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

json_get-1.0.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file json_get-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for json_get-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 621616e0ed34d1205f2b658915c413d87cfb08917cc2796e7b2677499db3161d
MD5 b3b6ee3d0abbe4e0d2551bb159b95026
BLAKE2b-256 46b37bb5d7c0954be671a3f372acba0329601f65c060b99d059f4713a5c3b0c0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page