JSON Patch Generator
Compare two JSON documents and generate RFC 6902 JSON Patch operation sets.
Preset Sample Payloads
Valid JSON
Valid JSON
Total Operations5 ops
Add / Replace / Remove2 add • 3 repl • 0 rem
Size A / Size B159 B / 216 B
Patch size389 B
JSON Patch Generator — create RFC 6902 patch documents from JSON diffs
RFC 6902 JSON Patch is a standard format for expressing a sequence of operations to apply to a JSON document. Each operation is an object with an op field (add, remove, replace, move,copy, or test), a path using JSON Pointer notation, and optionally a value. JSON Patch is used in REST APIs (PATCH requests), version control systems for JSON data, and anywhere a minimal diff representation is needed. This tool generates the minimal set of add, remove, and replace operations by recursively comparing two JSON documents.
Built and maintained by Meet Shah · Last updated
What this tool is used for
- Producing an RFC 6902 patch between two documents.
- Generating a PATCH body for an API that accepts JSON Patch.
- Understanding how a change is expressed as operations.
- Checking a patch before sending it to a live endpoint.
- Comparing JSON Patch against Merge Patch for one change.
Frequently Asked Questions
- What standard does the output follow?
- RFC 6902 JSON Patch — an array of operations, each with an `op` and a JSON Pointer `path`. The generator emits `add`, `remove` and `replace`, which covers every structural difference between two documents.
- Why are slashes in a key escaped?
- Because JSON Pointer uses `/` as its separator, so a key containing one has to be written `~1`, and a literal `~` becomes `~0`. Without that escaping a key such as `a/b` would be read as two levels of nesting.
- How are array changes handled?
- By index, position for position. That is correct and minimal for appends and in-place edits, but a single element inserted at the front makes every later index differ, producing a long patch where a human would describe one insertion.
- Does it emit move or copy operations?
- No. Both are in the specification, but detecting them requires matching relocated values across the document, and a patch built only from add, remove and replace applies to the same result.
- Where is JSON Patch actually used?
- HTTP PATCH bodies with `application/json-patch+json`, Kubernetes resource updates, and change feeds where sending the delta beats sending the document. The byte comparison shown tells you whether the patch is genuinely smaller.
- How does it differ from JSON Merge Patch?
- Merge Patch (RFC 7386) is a sparse copy of the document where `null` means delete — simpler, but it cannot express deleting a key by setting it to null, nor target an array element. JSON Patch is explicit and can do both.
Common errors and gotchas
- Confusing JSON Patch with JSON Merge Patch, which are different specifications and media types.
- Generating array operations by index, which break if the array changed since the patch was made.
- Omitting a `test` operation where the patch depends on a precondition.
- Escaping a path segment incorrectly, where `/` and `~` need encoding in a pointer.
- Assuming the server applies operations atomically, which the specification requires but not every server honours.
Related Developer Utilities tools
RegExp Tester
Test regular expressions and inspect matches locally.
Regex Visualizer
Visual regex pattern diagram with live match highlighting and capture group annotations.
Subnet Calculator
Compute CIDR subnets, usable hosts, and network ranges.
Cron Parser
Translate cron syntax into plain English.
URL Parser
Break a URL into protocol, host, path, and query parts.
HTML Previewer
Paste HTML and see it rendered live in a safe, sandboxed preview.
HTTP Status Code Reference
Search and look up every HTTP status code and its meaning.
MIME Type Lookup
Find the MIME type for a file extension, or the extensions for a MIME type.