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

Or drop a .json file here.
Members
1
Removals (null)
1
{
  "b": null
}

Supported formats

Input
text
Output
text

Privacy

Runs entirely in your browser. Your input is never uploaded, stored, or sent to a third party.

Processing
In your browser
Privacy level
Browser only

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

  1. Parse both values.
  2. Recurse over objects; emit changed leaves; emit `null` for a key missing from the target and present in the source.
  3. Treat arrays and primitives as atomic replacements.
  4. Serialise the result as the merge-patch object (null when unchanged).

Usage

  1. Paste the source JSON value.
  2. Paste the target JSON value.
  3. 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

jsonSelect to copy
{
  "source": "{\"a\":1,\"b\":2}",
  "target": "{\"a\":1}"
}

Nested change

jsonSelect to copy
{
  "source": "{\"user\":{\"name\":\"Ada\",\"age\":36}}",
  "target": "{\"user\":{\"name\":\"Ada\",\"age\":37}}"
}

Array replacement

jsonSelect to copy
{
  "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

  1. RFC 7396: JSON Merge Patch — IETF
  2. RFC 6902: JSON Patch — IETF