Skip to main content

python-json-patch-ext

PyPI version Supported Python versions

Applying JSON Patches in Python

This module extends the Python jsonpatch module to add 'check', 'mutate' and 'merge' operations.

See source code for examples

Example

from jsonpatchext import JsonPatchExt, JsonPatchTestFailed

def StartsWithComparator(current, compare):
    if not current.startswith(compare):
        msg = '{0} ({1}) does not starts with {2} ({3})'
        raise JsonPatchTestFailed(msg.format(current, type(current), compare, type(compare)))

def RemoveLastMutator(current, value):
    return current[:-1]

patch = JsonPatchExt([
    {'op': 'add', 'path': '/foo', 'value': {'bar': 'bar'}},
    {'op': 'check', 'path': '/foo/bar', 'value': 'bar', 'cmp': 'equals'},
    {'op': 'merge', 'path': '/foo', 'value': {'newbar': 'newbarvalue'}},
    {'op': 'check', 'path': '/foo/newbar', 'value': 'newb', 'cmp': 'custom', 'comparator': StartsWithComparator},
    {'op': 'mutate', 'path': '/foo/newbar', 'mut': 'uppercase'},
    {'op': 'mutate', 'path': '/foo/newbar', 'mut': 'custom', 'mutator': RemoveLastMutator},
])
doc = {}
result = patch.apply(doc)
print(result)

checkpatch = JsonPatchExt([
    {'op': 'check', 'path': '/foo/bar', 'value': 'bar', 'cmp': 'equals'},
    {'op': 'check', 'path': '/foo/newbar', 'value': 'NEWB', 'cmp': 'custom', 'comparator': StartsWithComparator},
])

result = checkpatch.check(result)
print(result)

Output:

{'foo': {'bar': 'bar', 'newbar': 'NEWBARVALU'}}
True

Author

Rangel Reale (rangelspam@gmail.com)

Metadata

Release files for jsonpatchext 1.39

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jsonpatchext 1.39
File Size Uploaded Provenance Actions
jsonpatchext-1.39.tar.gz 8.5 kB Without provenance Details for jsonpatchext-1.39.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for jsonpatchext 1.39
File Interpreter ABI Platform Actions
jsonpatchext-1.39-py2.py3-none-any.whl Python 3, Python 2 none any Details for jsonpatchext-1.39-py2.py3-none-any.whl

Total release size: 17.7 kB

Release files / jsonpatchext-1.39.tar.gz

Download URL jsonpatchext-1.39.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
5881f33d409139dd92e348b3bec4b377b4495958479ff517e4b39c5bead1bbee
BLAKE2b-256 checksum
How to use checksums
db8789e44561a7fe4e3bc6086e670381e4f9db9687f815037295bb70d53f61ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.0 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.6

Release files / jsonpatchext-1.39-py2.py3-none-any.whl

Download URL jsonpatchext-1.39-py2.py3-none-any.whl
Size 9.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
60a22d0517b8d5540c7956bf9119f1da9d52a1285e56448e20047bbd3944200a
BLAKE2b-256 checksum
How to use checksums
f4e1fd7d2865d813d46298daf4e5087ed6dfcc05f512150dfc80b6fd6a0e8846
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.0 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.6

Security for jsonpatchext 1.39

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page