JSON Patch Functions¶
JSON Patch (RFC 6902) and JSON Merge Patch (RFC 7396) functions.
Summary¶
| Function | Signature | Description |
|---|---|---|
json_diff |
object, object -> array |
Generate JSON Patch (RFC 6902) that transforms first object into second |
json_merge_patch |
object, object -> object |
Apply JSON Merge Patch (RFC 7396) to an object |
json_patch |
object, array -> object |
Apply JSON Patch (RFC 6902) operations to an object |
Functions¶
json_diff¶
Generate JSON Patch (RFC 6902) that transforms first object into second
Signature: object, object -> array
Examples:
# Replace value
json_diff({a: 1}, {a: 2}) -> [{op: 'replace', path: '/a', value: 2}]
# Add field
json_diff({a: 1}, {a: 1, b: 2}) -> [{op: 'add', path: '/b', value: 2}]
# Remove field
json_diff({a: 1, b: 2}, {a: 1}) -> [{op: 'remove', path: '/b'}]
json_merge_patch¶
Apply JSON Merge Patch (RFC 7396) to an object
Signature: object, object -> object
Examples:
# Merge objects
json_merge_patch({a: 1, b: 2}, {b: 3, c: 4}) -> {a: 1, b: 3, c: 4}
# Null removes field
json_merge_patch({a: 1}, {a: `null`}) -> {}
# Add to empty
json_merge_patch({}, {a: 1}) -> {a: 1}
json_patch¶
Apply JSON Patch (RFC 6902) operations to an object
Signature: object, array -> object
Examples: