Skip to main content

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)

Uploaded Source

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

Hashes for json-get-1.0.tar.gz
Algorithm Hash digest
SHA256 3512b625808233eee3cf1b5fa10500f03719ff844d656bdec240c22c24c07d84
MD5 01dd2bdfbca5246dcc7a5002853a30ad
BLAKE2b-256 d3265c92568634f2f639679f9b12ce81eff0f7216b5b02c1faad6ddb7ab5d03c

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