JSON Merge Patch
Generate an RFC 7396 JSON Merge Patch from a source and a target JSON value.
- Runs locally in your browser
- No upload required
Try it
Supported formats
Privacy
Runs entirely in your browser. Your input is never uploaded, stored, or sent to a third party.
1 member(s) in the merge patch, 1 of them a removal (null).
How it works
- Recursed over both objects and compared each member.
- Emitted a member only where the target differs.
- Represented a removed member as an explicit `null`, per RFC 7396.
- Arrays are atomic values in RFC 7396: any array change replaces the whole array rather than patching it element by element.
- A patch member value of `null` deletes that member from the target document; there is no way to set a member literally to null through a merge patch.
Methodology
- Parse both values.
- Recurse over objects; emit changed leaves; emit `null` for a key missing from the target and present in the source.
- Treat arrays and primitives as atomic replacements.
- Serialise the result as the merge-patch object (null when unchanged).
Usage
- Paste the source JSON value.
- Paste the target JSON value.
- Copy the generated RFC 7396 merge patch object.
Examples
These are examples, not current values: they use fixed inputs, while the interactive tool computes live results in your browser.
Change and removal
{
"source": "{\"a\":1,\"b\":2}",
"target": "{\"a\":1}"
}Nested change
{
"source": "{\"user\":{\"name\":\"Ada\",\"age\":36}}",
"target": "{\"user\":{\"name\":\"Ada\",\"age\":37}}"
}Array replacement
{
"source": "{\"tags\":[\"a\",\"b\"]}",
"target": "{\"tags\":[\"a\",\"c\"]}"
}Limitations
When to use a merge patch
A JSON Merge Patch (media type `application/merge-patch+json`) describes an update as a partial document that is merged into the target. `null` deletes a member, which makes it a good fit for configuration updates and deep object edits.
Because arrays are atomic, a merge patch is a poor fit when you need to edit one element of a large list: use JSON Patch for that.
Frequently asked questions
- How is this different from JSON Patch?
- A JSON Merge Patch is a partial document where null means delete, so it is smaller and simpler for deep objects, but it cannot express array element changes or set a key to null.
- Why did my whole array get replaced?
- That is RFC 7396: arrays are values, not containers to merge into, so any difference replaces the array.
Sources
- RFC 7396: JSON Merge Patch — IETF
- RFC 6902: JSON Patch — IETF
Send feedback
Tell us if this tool helped, report a problem, or suggest a tool. Only the message you type is sent — never the input you used in the tool.
Was this tool useful?
Prefer to write to us directly? See the contact page.