JSON Patch Generator
Compare two JSON documents and get the RFC 6902 patch that turns the first into the second. Everything runs in your browser.
What this tool does
It compares two JSON documents and writes the list of operations that turns the first into the second, in the format defined by RFC 6902. Instead of sending a whole document to say that one field changed, you send the change itself.
When to use it
Use it to build the body of a PATCH request, to record what changed between two versions of a configuration file, or to store an audit trail that is far smaller than keeping every full copy. It is also a quick way to find out what actually differs between two documents that look the same.
The operations it produces
| Operation | What it means |
|---|---|
| add | Adds a value where there was none, or inserts into an array. |
| remove | Deletes the value at that location. |
| replace | Overwrites the value at a location that already exists. |
| move | Moves a value from one location to another. |
| copy | Copies a value to another location. |
| test | Checks a value and aborts the whole patch if it does not match. |
This tool writes add, remove and replace only. Those three can express any change, and a patch you can read line by line is worth more than a shorter one you have to puzzle over. The other three are part of RFC 6902 and any compliant server will accept them.
How the paths work
Each path is a JSON Pointer (RFC 6901): a slash-separated route from the root of the document, where “/address/zipCode” means the zipCode field inside address. Array positions are numbers, so “/skills/0” is the first item, and a dash means the end of the array: “/skills/-” appends. Because the slash is the separator, a key that contains one is written as ~1, and a literal tilde as ~0.
Notes on the output
The diff is literal: it compares values position by position, so inserting an item at the start of an array produces a replace on every item after it rather than a single insert. For arrays of objects with stable identifiers, a patch generated from the identifiers will always be smaller than one generated from positions.
How to generate a JSON Patch
Paste two JSON documents and generate the patch.
- Paste the original JSON on the left.
- Paste the updated JSON on the right.
- Click Generate, then copy the patch.
FAQ
Does this tool upload my data?
No. Both documents stay in your browser and the patch is generated on your own machine.
Is the output RFC 6902 compliant?
Yes. Every operation is an object with op, path and — for add and replace — value, and the paths are JSON Pointers as RFC 6901 defines them.
Does it include move and copy operations?
No. It writes add, remove and replace, which are enough to express any change and are far easier to read. A move is simply a remove followed by an add.
How do I apply the patch?
Send it to an API that accepts application/json-patch+json, or use a library: jsonpatch in Python, json-patch in JavaScript, JsonPatchDocument in .NET, json-patch in Java, and so on.
What is the difference from JSON Merge Patch?
JSON Merge Patch (RFC 7386) looks like the document itself, with null meaning “delete”. That makes it easy to read but unable to store a real null or to touch a single item in an array. JSON Patch is more verbose and can express anything.
Wikipedia — JSON Patch
Wikipedia — JSON
Wikipedia — Patch (computing)
Wikipedia — Diff
Wikipedia — REST