pyjsonpatch
About
A Python implementation of JSON Pointer (RFC 6902) and JSON Patch (RFC 6902). Primarily, the package can do the following to Python object(s) representing JSON(s):
apply_patchto modify an object with a JSON patchgenerate_patchto generate a JSON Patch from two objectsget_by_ptrto retrieve a value from object using a JSON pointer
Table of Contents
Installation
Python 3.8 or higher is required. You can install the library with:
# Linux/macOS
python3 -m pip install -U pyjsonpatch
# Windows
py -3 -m pip install -U pyjsonpatch
Development
Install the dev requirements with:
# Linux/macOS
python3 -m pip install -r requirements-dev.txt
# Windows
py -3 -m pip install -r requirements-dev.txt
Linting and Formatting
Run the Ruff linter and formatter with:
# Lint
ruff check --fix
# Format
ruff format
Testing
Run tests with:
# Linux/macOS
python3 -m unittest discover tests
# Windows
py -3 -m unittest discover tests
Building and Releasing
Build with:
# Linux/macOS
python3 -m build
# Windows
py -3 -m build
Commit messages should follow Conventional Commits and version numbers follow Semantic Versioning. Releases require a version bump in pyproject.toml alongside a push to main with that version as a tag.
Examples
get_by_ptr
from pyjsonpatch import get_by_ptr
source = {"": 1, "foo": [2, 3]}
print(get_by_ptr(source, "").obj)
# {"": 1, "foo": [2, 3]}
print(get_by_ptr(source, "/").obj)
# 1
print(get_by_ptr(source, "/foo").obj)
# [2, 3]
print(get_by_ptr(source, "/foo/0").obj)
# 2
apply_patch
from pyjsonpatch import apply_patch
source = {"": 1, "foo": [2, 3]}
patch = [
{"op": "add", "path": "/hello", "value": "world"},
{"op": "add", "path": "/foo/1", "value": 4},
{"op": "add", "path": "/foo/-", "value": 5},
{"op": "remove", "path": "/"},
]
res = apply_patch(source, patch)
print(res.obj)
# {"foo": [2, 4, 3, 5], "hello": "world"}
print(res.obj is source)
# True
# - source was mutated
print(res.removed)
# [None, None, None, 1]
# - Only the 4th operation removes something
generate_patch
from pyjsonpatch import generate_patch
source = {"": 1, "foo": [2, 3]}
target = {"foo": [2, 4], "hello": "world"}
print(generate_patch(source, target))
# [
# {"op": "remove": "path": "/"},
# {"op": "replace": "path": "/foo/1", "value": 4},
# {"op": "add": "path": "/hello", "value": "world"},
# ]
Metadata
Release files for pyjsonpatch 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyjsonpatch-0.1.3.tar.gz | 15.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyjsonpatch-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 29.4 kB
Release files / pyjsonpatch-0.1.3.tar.gz
| Download URL | pyjsonpatch-0.1.3.tar.gz |
|---|---|
| Size | 15.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0273fe6984fbfe7628d58f86e63c602c0a816e7c112a479970f3828928c573e1
|
|
BLAKE2b-256 checksum How to use checksums |
d5f773c66854ceb178ecc8d87003c0a384b2d8e7665aa542a210d32affe917d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 25, 2025.
Transparency logRelease files / pyjsonpatch-0.1.3-py3-none-any.whl
| Download URL | pyjsonpatch-0.1.3-py3-none-any.whl |
|---|---|
| Size | 14.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
23de20db16308db5df0fb70f5beaf9e86af74f7b1dacdf89580a74f2d080b54d
|
|
BLAKE2b-256 checksum How to use checksums |
946b47bd557d73d81731557f37ff5a95fdcca72371723d556a19a133c07167e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 25, 2025.
Transparency log