Skip to content

Add JSONPatch.atomic and clarify docs#130

Merged
jg-rp merged 4 commits into
mainfrom
fix-129
Jun 26, 2026
Merged

Add JSONPatch.atomic and clarify docs#130
jg-rp merged 4 commits into
mainfrom
fix-129

Conversation

@jg-rp

@jg-rp jg-rp commented Jun 25, 2026

Copy link
Copy Markdown
Owner

This PR adds patch.atomic(patch, data) and JSONPatch.atomic(data). atomic() is similar to apply(), but preserves input data if a patch operation fails.

See #129

@jg-rp jg-rp changed the title Add JSONPatch.patch and clarify docs Add JSONPatch.atomic and clarify docs Jun 25, 2026
@msfrucht

Copy link
Copy Markdown

I downloaded the patch branch and re-ran the same test. It is working as expected, function JSONPatch.atomic is RFC6902 compliant of JSON document is unchanged on any error in the operation list.

import copy
from jsonpath import JSONPatch, JSONPatchError, JSONPatchTestFailure
test_dict = {"a":{"b":{"c": 1}}}
patcher = JSONPatch(ops=[
       { "op": "replace", "path": "/a/b/c", "value": 42 },
       { "op": "test", "path": "/a/b/c", "value": "C" }
     ])
test_copy = copy.deepcopy(test_dict)
patcher.atomic(test_dict) # raised exception as expected
test_dict == test_copy
True
print(test_dict)
{'a': {'b': {'c': 1}}}
print(test_copy)
{'a': {'b': {'c': 1}}}

@jg-rp jg-rp merged commit 6203888 into main Jun 26, 2026
28 checks passed
@jg-rp jg-rp deleted the fix-129 branch June 26, 2026 06:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants