jsonyx.apply_patch¶
- jsonyx.apply_patch(obj, patch, *, allow=NOTHING, use_decimal=False)[source]¶
Apply a JSON patch to a Python object.
Added in version 2.0.
- Parameters:
obj (
Any) – a Python objectpatch (_Operation |
list[_Operation]) – a JSON patchallow (
Container[str], default:NOTHING) – the JSON deviations fromjsonyx.allowuse_decimal (
bool, default:False) – usedecimal.Decimalinstead offloat
- Raises:
AssertionError – if an assertion fails
IndexError – if an index is out of range
JSONSyntaxError – if a query is invalid
KeyError – if a key is not found
TypeError – if a value has the wrong type
ValueError – if a value is invalid
- Returns:
Any– the patched Python object
- Example:
>>> import jsonyx as json >>> json.apply_patch([1, 2, 3], {"op": "del", "path": "$[1]"}) [1, 3]
Tip
Using a filter instead of an index is more robust.