Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

License

NotificationsYou must be signed in to change notification settings

jg-rp/python-jsonpath

Repository files navigation

A flexible JSONPath engine for Python.
We followRFC 9535 and test against theJSONPath Compliance Test Suite.

LicenseTestsPyPI - Downloads
PyPi - VersionPython versions


Table of Contents

Install

Install Python JSONPath usingpip:

pip install python-jsonpath

OrPipenv:

pipenv install -u python-jsonpath

Or fromconda-forge:

conda install -c conda-forge python-jsonpath

Links

Related projects

  • JSONPath RFC 9535 - A Python implementation of JSONPath that follows RFC 9535 much more strictly. If you require maximum interoperability with JSONPath implemented in other languages - at the expense of extra features - choosejsonpath-rfc9535 overpython-jsonpath.

    jsonpath-rfc9535 matches RFC 9535's JSONPath model internally and is careful to use the spec's terminology. It also includes utilities for verifying and testing theJSONPath Compliance Test Suite. Most notably the nondeterministic behavior of some JSONPath selectors.

  • JSON P3 - RFC 9535 implemented in TypeScript. JSON P3 does not include all the non-standard features of Python JSONPath, but does define some optionalextra syntax.

  • Ruby JSON P3 - RFC 9535, RFC 6901 and RFC 6902 implemented in Ruby.

Examples

JSONPath

importjsonpathdata= {"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

We include anRFC 6901 compliant implementation of JSON Pointer. See JSON Pointerquick start,guide andAPI reference

fromjsonpathimportpointerdata= {"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)# 100jane_score=pointer.resolve(["users",3,"score"],data)print(jane_score)# 55

JSON Patch

We also include anRFC 6902 compliant implementation of JSON Patch. See JSON Patchquick start andAPI reference

fromjsonpathimportpatchpatch_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 theMIT license.

Sponsor this project

 

Contributors2

  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp