JSON Patch (RFC 6902) Generator & Applier
Diff two JSON documents into an applyable patch, or apply an existing patch to a document
add, remove, replace, move, copy, test) that transforms one JSON document into another — the standard format behind HTTP PATCH requests with a Content-Type: application/json-patch+json body. Array diffs here are positional, not LCS-aligned — an insertion in the middle of a long array may show as several replaces rather than one clean insert, though the resulting patch is still fully correct when applied.About this tool
The ToolNinja JSON Patch tool implements RFC 6902 in both directions: Generate mode diffs two JSON documents into an actual applyable patch (an array of add/remove/replace operations with JSON Pointer paths), and Apply mode takes a document and a patch and produces the resulting document — or a specific error if the patch doesn't match what it expected to find. JSON Patch is the format behind a real HTTP PATCH request body with Content-Type: application/json-patch+json — rather than resending the whole resource (as a PUT would) or inventing a bespoke partial-update schema, the client sends exactly the operations that changed. This tool generates that patch directly from two example documents (a realistic 'before' and 'after'), which is usually faster than hand-writing the operations and their JSON Pointer paths from scratch. Apply mode supports the full RFC 6902 operation set (add, remove, replace, move, copy, test) — not just what this tool's own generator produces — so it works on a patch from any source: hand-written, from another tool, or from a library like fast-json-patch.
When to use it
- →Generating the JSON Patch body for a REST API's PATCH endpoint from a before/after example
- →Understanding exactly what operations a patch library produced before shipping it
- →Applying a patch someone sent you to see the resulting document without writing code
- →Debugging why a patch fails against a document — the apply error names the exact path and what it expected to find
Tips
- ◆Array diffs are positional, not LCS-aligned — inserting one item in the middle of a long array may show as several replace operations instead of a single clean insert. The resulting patch is still fully correct when applied, just not the shortest possible one.
- ◆A path of "" (empty string) in a patch means the whole document — add or replace at the root path replaces the entire document in one operation.
- ◆The 'test' operation lets a patch assert a precondition before making changes — if the asserted value doesn't match, applying stops with a clear error instead of silently corrupting the document.
Frequently asked questions
What's the difference between JSON Patch (RFC 6902) and JSON Merge Patch (RFC 7396)?
JSON Patch is a list of explicit, ordered operations (add/remove/replace/move/copy/test) with JSON Pointer paths — precise, but more verbose. JSON Merge Patch is just a partial JSON object merged into the target, which is more compact but can't express removing a key (it uses null for that) and can't target specific array elements at all. JSON Patch is the right choice whenever you need to operate on arrays or need the precondition-checking 'test' operation.
Why did my patch fail to apply with a "does not exist" error?
The document you're patching doesn't match what the patch expects at that path — usually because the patch was generated against a different version of the document than the one you're applying it to. The error names the exact path, which is the fastest way to spot where the two versions diverged.
Does array diffing produce the shortest possible patch?
No — this tool diffs arrays positionally (index by index), not with an LCS (longest common subsequence) alignment the way a true 'minimal diff' algorithm would. A single insertion in the middle of a long array can show up as a run of replace operations rather than one insert. The patch is always correct when applied, just not always the most compact representation of the change.