FormatterHQ

JSON Patch Generator (Diff to Patch)

Paste an original and a modified JSON document to get the list of add, remove and replace operations that transforms one into the other, ready to send as application/json-patch+json.

Loading tool…
Ready.

How to use the JSON Patch Generator (Diff to Patch)

  1. Paste the current version into Original JSON.
  2. Paste the desired version into Modified JSON.
  3. Tick Add "test" guards before changes if the patch should fail when the original has changed in the meantime.
  4. Click Generate patch and copy the RFC 6902 operations from the output panel.

Create a patch from two documents with the JSON patch generator

This JSON patch generator compares two JSON documents and writes the RFC 6902 operations that transform the first into the second. Instead of hand-writing add, remove and replace entries with JSON Pointer paths, you edit a copy of the document and let the tool work out the difference.

The output is a JSON array you can send in an HTTP PATCH request with Content-Type: application/json-patch+json, store as a migration step, or feed to kubectl patch --type json.

Example

Original:

{"id": 7, "name": "Widget", "price": 10, "tags": ["a", "b", "c"], "meta": {"color": "red"}}

Modified:

{"id": 7, "name": "Widget Pro", "price": 10, "tags": ["a", "c"], "meta": {"color": "red", "size": "L"}, "active": true}

Generated patch:

[
  { "op": "replace", "path": "/name", "value": "Widget Pro" },
  { "op": "replace", "path": "/tags/1", "value": "c" },
  { "op": "remove", "path": "/tags/2" },
  { "op": "add", "path": "/meta/size", "value": "L" },
  { "op": "add", "path": "/active", "value": true }
]

Unchanged values (id, price, meta.color) produce no operations. If the two documents are equal, the output is an empty array [] and the status says the documents are identical.

How the diff is computed

  • Objects are compared key by key. Keys missing from the modified document become remove, new keys become add, and shared keys are compared recursively.
  • Key order is ignored. {"a": 1, "b": 2} and {"b": 2, "a": 1} are treated as equal.
  • Arrays are compared position by position. Changed positions become replace, extra items at the end are removed from the last index backward, and new items are appended with /-.
  • Type changes, such as a string becoming an object, produce a single replace of the whole value.

Because arrays are aligned by index, removing the second of three items shows up as "replace index 1, remove index 2" rather than "remove index 1". Both are correct and give the same result; the positional form is simply more predictable.

The test guard option

With Add "test" guards before changes ticked, every replace and remove is preceded by a test that checks the old value:

[
  { "op": "test", "path": "/price", "value": 10 },
  { "op": "replace", "path": "/price", "value": 12 }
]

If someone else changed price before your patch arrives, the test fails and a compliant server rejects the whole patch. This is a lightweight form of optimistic concurrency control when you cannot use ETags.

Tips

  • Check a generated patch by applying it to the original in the JSON Patch tester; the result should equal your modified document.
  • If you only need a visual comparison, JSON diff shows changes side by side.
  • If the receiving API expects a partial document rather than operations, create an RFC 7396 patch with JSON Merge Patch instead.

Privacy

The comparison runs locally in your browser, so both documents stay on your machine.

Frequently asked questions

Is the generated patch the smallest possible?
It is minimal for objects but not always for arrays, because arrays are compared by position rather than by searching for moved items. The patch is always correct, and applying it to the original gives the modified document.
Does the generator produce move or copy operations?
No. It only emits add, remove and replace, plus test when guards are enabled. These three are enough to describe any change and are supported by every JSON Patch library.
Why are removed array items deleted from the end first?
Removing an item shifts every later index. Deleting from the highest index down keeps the remaining paths valid while the patch is applied in order.
What are test guards for?
They make the patch conditional. Each change is preceded by a test of the current value, so the patch fails instead of overwriting data that someone else modified after you read it.

Last updated October 3, 2026

Guides

Related tools

Random JSON Generator Generate realistic fake JSON test data — names, emails, addresses, dates and more — with custom fields. JSON Merge Patch (RFC 7396) Apply an RFC 7396 JSON Merge Patch to a document, or create the merge patch that turns one JSON document into another. JSON Patch Tester (RFC 6902) Apply RFC 6902 JSON Patch operations (add, remove, replace, move, copy, test) to a document and see exactly which step fails. JSON Path Finder Click any value in a JSON tree to get its path as JSONPath, JavaScript, Python, PHP, jq or JSON Pointer — or list every path. JSON Pretty Print Pretty print JSON online with a 4-space default, 2 or 3 spaces or tabs, and see the matching JavaScript, Python, PHP and jq commands. JSON Reader Open a .json file in your browser and read it as a collapsible tree, a sortable table or a graph, with a filter to find any value. JSON Schema to Sample JSON Generate realistic fake JSON that conforms to a JSON Schema — formats, enums, ranges and required fields respected. JSON Schema Validator Validate JSON against a JSON Schema (draft-07, 2019-09, 2020-12) with Ajv and get every error with its path and rule. JSON Serialize Online Serialize JSON into its most compact transport form, optionally wrapped as an escaped string literal for storage or messaging. JSON Sorter Sort JSON keys alphabetically at every level, ascending or descending. Optionally sort arrays of values for clean, comparable output. JSON Stringify Online Stringify JSON into an escaped string literal, exactly like JSON.stringify. Ready to embed JSON inside JSON, code or config values. JSON Syntax Highlighter Syntax highlight JSON with light, dark or Monokai themes and copy the colourised HTML for blogs, docs and slides.