Generate RFC 6902 JSON Patches Instantly with JSON Patch Generator
The JSON Patch Generator compares two JSON documents in your browser and outputs valid RFC 6902 patch operations for any PATCH endpoint.
Table of Contents
Every modern REST API that lets clients modify resources has to answer one question: how does the client tell the server exactly what changed? Sending the entire document back is wasteful, and ad-hoc merge logic breaks the moment a field is added or removed. That is precisely the problem RFC 6902 β JSON Patch β was designed to solve, and it is exactly what the JSON Patch Generator makes effortless.
The tool takes two JSON documents side by side β an original (source) and an updated (target) β and produces a clean array of patch operations that, when applied to the source, reconstructs the target. No server round-trips, no data leaving your browser, no sign-up. Paste, compare, copy.
Whether you are wiring up a PATCH /users/42 endpoint, auditing configuration drift between environments, or synchronising state across systems, a correct JSON Patch is the cleanest contract between client and server. This guide walks through how the generator works, the RFC standards behind it, and practical patterns you can apply today.
Why Use JSON Patch Generator?
- Runs entirely in your browser. The diffing logic executes client-side, so your data never touches a server. That makes the tool safe for proprietary configs, PII-laden documents, and anything else you would rather not paste into a random SaaS.
- Standards-correct output. Every operation it emits follows RFC 6902, and every path uses RFC 6901 JSON Pointer escaping. The result plugs straight into compliant libraries like fast-json-patch, json-patch, or a hand-rolled endpoint.
- Handles nested structures. The recursive diff walks deeply nested objects and arrays, so you get granular paths like /address/city rather than a coarse "the object changed" summary.
- Copy-and-go workflow. One click copies the patch array to your clipboard, ready to paste into a request body, a test fixture, or a migration script.
- No setup, no dependencies. There is nothing to install or configure. Open the page, paste two documents, and you have a patch. Great for pair-debugging or quick ad-hoc comparisons.
- Clear add/remove/replace model. Because the tool limits itself to the three structural operations most PATCH endpoints use, the output is readable, reviewable, and easy to reason about during code review.
Key Features
| Feature | What it does |
|---|---|
| Side-by-side input | Two textareas let you paste the original and updated JSON documents for direct comparison. |
| Recursive diff engine | A compareJson function walks objects and arrays to produce the minimal set of operations. |
| RFC 6901 path escaping | Special characters ~ and / are correctly escaped so paths are always valid. |
| /- array-append support | Extra target array items are added using the standard append-pointer syntax. |
| Copy to clipboard | One click copies the formatted patch array for immediate use in your request or script. |
| 100% client-side | No network calls β your data stays in the browser, always. |
- The clear/reset buttons let you wipe both inputs and start over without reloading the page.
- The output is rendered as a pretty-printed JSON array, so it is immediately readable and valid for re-parsing.
- Because it runs locally, the tool works offline once the page is loaded β handy for air-gapped environments or in-flight coding.
How to Use
- Open the tool at JSON Patch Generator.
- Paste your original document into the "Original JSON" textarea on the left.
- Paste your updated document into the "Updated JSON" textarea on the right.
- Compare β the tool runs the diff automatically and renders the resulting patch array below the inputs.
- Copy the output to your clipboard, then send it as the body of a PATCH request or apply it with your favourite patch library.
Understanding JSON Patch (RFC 6902)
RFC 6902 defines six operations, but the three structural ones cover the vast majority of real-world mutations and are exactly what this generator emits:
- add β inserts a new value at a path, or appends to an array using the special pointer /-.
- remove β deletes the value at a path (the key, array element, or nested member disappears).
- replace β overwrites the value at a path with a new one.
Each operation is a small JSON object with an op, a path, and (for add and replace) a value. Paths are written as JSON Pointers per RFC 6901, beginning with / and walking down the document tree β for example, /users/0/email points at the email field of the first user.
Two escaping rules matter: the tilde ~ becomes ~0, and the slash / becomes ~1. So a literal object key like a/b is written as /a~1b in a pointer. The generator handles this automatically, so even keys with awkward characters produce valid paths.
A concrete example makes it click. Given the source {"name": "Ada", "role": "dev"} and the target {"name": "Ada", "role": "lead", "team": "platform"}, the generator produces:
[
{ "op": "replace", "path": "/role", "value": "lead" },
{ "op": "add", "path": "/team", "value": "platform" }
]
For arrays, appending a new item uses the /- pointer. If the source is [1, 2] and the target is [1, 2, 3], you get:
[{ "op": "add", "path": "/-", "value": 3 }]
Practical Use Cases
REST PATCH Endpoints
The canonical use case. Your frontend edits a record; instead of sending the whole object back, it computes a patch against the original and PATCHes it to the server. The server applies each operation atomically, returning 200 OK or 204 No Content. The result is smaller payloads, clearer intent, and simpler audit trails.
Configuration Diffing
Comparing a staging config against production is a frequent, error-prone chore. Paste both into the generator and you instantly see every add, remove, and replace as discrete operations β far easier to review in a change ticket than a wall of unified-diff text. It turns "what changed?" into a machine-readable answer.
State Synchronisation
Real-time apps that sync client and server state (collaborative editors, dashboards, offline-first mobile apps) often transmit patches rather than full documents to cut bandwidth and resolve conflicts. The generator lets you prototype these patch streams quickly by inspecting what a real diff looks like before you commit to a transport.
Audit Logging and Replay
Storing the patch alongside each revision gives you a compact, replayable history of a document. To reconstruct any past state, apply the chain of patches in order; to revert, invert the operations. Generating those patches by hand is tedious β the tool removes the busywork from producing your initial fixtures and test cases.
Best Practices
- Diff against a stable source of truth. Both documents should be serialised the same way (same key order is not required, but same data model is) so the patch reflects real changes, not formatting noise.
- Prefer replace over remove+add. Where the generator emits replace, keep it β it is semantically clearer and typically cheaper to apply.
- Validate before you send. Run the generated patch through a local RFC 6902 library against the original to confirm it reconstructs the target exactly. This catches edge cases around array ordering and key escaping.
- Keep patches small and focused. If a diff balloons, reconsider whether a PUT of the whole resource would be simpler. Patches shine for surgical changes.
- Mind array semantics. RFC 6902 arrays are positional; reordering triggers a cascade of remove/add ops. If order is not meaningful, sort both inputs before diffing to keep the patch minimal.
- Never hard-code raw paths you have not tested β especially when keys may contain / or ~. Let the tool (or a library) do the escaping.
Start Patching Smarter
Stop hand-writing patch operations and double-guessing your pointers. Paste your documents into the JSON Patch Generator, copy the output, and ship a correct RFC 6902 patch in seconds β all without your data ever leaving the browser.
Related Tools You Might Like
- JSON Formatter β pretty-print and validate your documents before diffing them.
- JSON Deep Diff β a deeper, human-readable structural comparison when you need more than ops.
- Diff Checker β a general-purpose text diff for non-JSON content.
Happy patching!