Skip to main content

JSONPath, JSON Pointer and JSON Patch for Python.

Project description

Python JSONPath

A flexible JSONPath engine for Python with JSON Pointer and JSON Patch.

License Tests PyPI - Downloads
PyPi - Version Python versions


Table of Contents

Install

Install Python JSONPath using pip:

pip install python-jsonpath

Or Pipenv:

pipenv install -u python-jsonpath

Or from conda-forge:

conda install -c conda-forge python-jsonpath

Links

Examples

JSONPath

import jsonpath

data = {
    "users": [
        {"name": "Sue", "score": 100},
        {"name": "John", "score": 86},
        {"name": "Sally", "score": 84},
        {"name": "Jane", "score": 55},
    ]
}

user_names = jsonpath.findall("$.users[?@.score < 100].name", data)
print(user_names) # ['John', 'Sally', 'Jane']

JSON Pointer

Since version 0.8.0, we include an RFC 6901 compliant implementation of JSON Pointer. See JSON Pointer quick start, guide and API reference

from jsonpath import pointer

data = {
    "users": [
        {"name": "Sue", "score": 100},
        {"name": "John", "score": 86},
        {"name": "Sally", "score": 84},
        {"name": "Jane", "score": 55},
    ]
}

sue_score = pointer.resolve("/users/0/score", data)
print(sue_score)  # 100

jane_score = pointer.resolve(["users", 3, "score"], data)
print(jane_score)  # 55

JSON Patch

Since version 0.8.0, we also include an RFC 6902 compliant implementation of JSON Patch. See JSON Patch quick start and API reference

from jsonpath import patch

patch_operations = [
    {"op": "add", "path": "/some/foo", "value": {"foo": {}}},
    {"op": "add", "path": "/some/foo", "value": {"bar": []}},
    {"op": "copy", "from": "/some/other", "path": "/some/foo/else"},
    {"op": "add", "path": "/some/foo/bar/-", "value": 1},
]

data = {"some": {"other": "thing"}}
patch.apply(patch_operations, data)
print(data) # {'some': {'other': 'thing', 'foo': {'bar': [1], 'else': 'thing'}}}

License

python-jsonpath is distributed under the terms of the MIT license.

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

python_jsonpath-0.10.3.tar.gz (38.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_jsonpath-0.10.3-py3-none-any.whl (49.0 kB view details)

Uploaded Python 3

File details

Details for the file python_jsonpath-0.10.3.tar.gz.

File metadata

  • Download URL: python_jsonpath-0.10.3.tar.gz
  • Upload date:
  • Size: 38.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.2

File hashes

Hashes for python_jsonpath-0.10.3.tar.gz
Algorithm Hash digest
SHA256 15704ab755883acb6ec85c63b687b2a8cff1902cd293d4509f9e673423b431ee
MD5 001c7529f8f7b0495d2a739a3573d32b
BLAKE2b-256 6e944f7d3c7b82bec09d3fe9267aeac27d102654ec942f74d823c4565973d5d0

See more details on using hashes here.

File details

Details for the file python_jsonpath-0.10.3-py3-none-any.whl.

File metadata

File hashes

Hashes for python_jsonpath-0.10.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2af2f897d30190e53097eb0f3e93031c058bd6facf998517b6dfc77af367ecf4
MD5 66a913c1658456dcaebda9104b88562f
BLAKE2b-256 4e87fe0ea6268b9a07b3fc14f23b1a5427b0605eae09d23fafe8468a2ac4b4c5

See more details on using hashes here.

Supported by

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