dictutils.ops.patch¶
- dictutils.ops.patch(d, ops)[source]¶
Apply JSON-Patch-like operations to an object.
- Parameters:
- Return type:
- Returns:
The patched object
Example
>>> import json >>> data = {"user": {"name": "Alice", "age": 30}} >>> operations = [ ... {"op": "replace", "path": "user.age", "value": 31}, ... {"op": "add", "path": "user.email", "value": "alice@example.com"}, ... {"op": "remove", "path": "user.age"} ... ] >>> result = patch(data, operations) >>> print(json.dumps(result, indent=4)) { "user": { "name": "Alice", "email": "alice@example.com" } }