An implementation of the JSON Merge Patch RFC 7396.
JSON Merge Patch (RFC 7396) is a standard format that allows you to update a JSON document by sending the changes rather than the whole document. JSON Merge Patch plays well with the HTTP PATCH verb (method) and REST style programming.
There are three functions (merge
, apply
, and generate
) for manipulating JSON objects. These functions are used for applying patches to JSON objects, merging JSON objects, and generating patches based on differences between JSON objects.
jsonMergePatch.merge
Merges a patch JSON object into an original JSON object. If either the original or the patch is not a valid JSON object, it returns a deep clone of the patch.
Json
: Represents any valid JSON value.original
: The original JSON object to be merged.patch
: The patch JSON object to merge into the original.Json
object that is the merged result.jsonMergePatch.apply
Applies a patch to a target JSON object. If the patch or the target is not a valid JSON object, the target is replaced with a deep clone of the patch.
Json
: Represents any valid JSON value.target
: The target JSON object to which the patch will be applied.patch
: The patch JSON object to apply to the target.jsonMergePatch.generate
Generates a patch JSON object that represents the differences between the original and result JSON objects. If either the original or the result is not a valid JSON object, it returns a deep clone of the result.
Json
: Represents any valid JSON value.original
: The original JSON object.result
: The resulting JSON object to compare with the original.