JSON Patch Generator
JSON Patch (RFC 6902)
No patch generated yet.
JSON Patch / Diff Generator (RFC 6902)
The JSON Patch Generator creates RFC 6902 patch operations that describe how to transform one JSON document into another. JSON Patch is the standard for representing changes as a list of operations like add, remove, and replace. It is widely used in APIs for partial updates and in data pipelines that need to transmit only the differences. This tool helps you generate and apply patches quickly, with readable output and a clear workflow.
Instead of sending an entire JSON object when only a few fields change, JSON Patch lets you send a compact list of operations. This is more efficient and easier to audit. It also provides a reliable format for change logs, syncing data between services, and building UI-driven edits for complex objects. Everything runs locally in your browser, so your JSON never leaves your device.
What JSON Patch includes
- add adds a new value at a path.
- remove deletes a value at a path.
- replace updates a value at a path.
- move moves a value from one path to another.
- copy copies a value from one path to another.
- test asserts a value at a path (for conditional updates).
How to use the JSON Patch tool
- Paste the original JSON in the left editor.
- Paste the updated JSON in the right editor.
- Click Generate Patch to create RFC 6902 operations.
- Optionally apply the patch to verify the output.
Example: generating a patch
Original JSON:
{
"id": 7,
"name": "Avi",
"status": "active",
"roles": ["editor"]
}
Updated JSON:
{
"id": 7,
"name": "Avi",
"status": "inactive",
"roles": ["editor", "admin"],
"email": "avi@example.com"
}
Generated JSON Patch:
[
{ "op": "replace", "path": "/status", "value": "inactive" },
{ "op": "add", "path": "/roles/1", "value": "admin" },
{ "op": "add", "path": "/email", "value": "avi@example.com" }
]
Understanding JSON Pointer paths
JSON Patch uses JSON Pointer syntax for paths. For example, /roles/1 points to the second item in an array, and /profile/name points to a nested object value. If your key contains a / or ~, it must be escaped as ~1 and ~0 respectively.
Common errors and solutions
- Invalid JSON: Patch generation requires valid JSON on both sides. Validate inputs with JSON Validator before generating patches.
- Path not found: A
removeorreplaceoperation fails if the path does not exist. Ensure the path matches the original document. - Array index errors: Using an out-of-range index in a path causes failure. Use
-for appending to an array in anaddoperation. - Test operation failure:
testfails if the current value does not match. This is expected behavior; update the value or remove the test operation. - Escaping issues: Keys with slashes must be escaped in JSON Pointer (e.g.,
role/namebecomes/role~1name).
Best practices for JSON Patch
- Keep patches small and targeted for better performance and clarity.
- Use
testoperations when you need safe, conditional updates. - Validate the patch output by applying it to the original JSON before deployment.
- Store patches in logs for auditing and debugging.
- Use JSON Compare to inspect differences visually before patching.
When JSON Patch is the best choice
Use JSON Patch when you want precise, explicit changes. It is ideal for APIs that support PATCH requests, collaborative editors that track edits, and systems that need audit trails for data changes. Because each operation is explicit, patches are easy to store, replay, and review.
If you only need to send partial objects without explicit operations, consider JSON Merge Patch instead. JSON Patch is more verbose but also more expressive, especially when you need to remove fields, move items, or test values before applying changes.
Patch validation checklist
- Validate both JSON inputs before generating a patch.
- Review each operation to ensure paths are correct.
- Apply the patch to confirm it produces the expected output.
- Use
testto prevent accidental overwrites.
Example: remove and move operations
Original JSON:
{
"user": { "name": "Avi", "role": "admin" },
"flags": ["alpha", "beta"]
}
Updated JSON:
{
"user": { "name": "Avi" },
"flags": ["beta", "alpha"]
}
Possible patch:
[
{ "op": "remove", "path": "/user/role" },
{ "op": "move", "from": "/flags/0", "path": "/flags/1" }
]
This demonstrates how patch operations can remove fields and reorder array elements without sending the full document.
JSON Patch vs JSON Diff output
JSON Patch is an instruction list you can apply to a document. A visual diff is easier for humans to read, but it is not always machine-applicable. Use JSON Patch when you need programmatic updates or API PATCH requests, and use JSON Compare for a visual side-by-side review.
Because JSON Patch is standardized, it is also language-agnostic. The same patch can be applied in JavaScript, Python, Java, or C# using common libraries.
FAQs
What is JSON Patch used for?
It represents changes between JSON documents as operations, making it ideal for partial updates and sync.
Is JSON Patch the same as JSON Merge Patch?
No. JSON Patch uses a list of operations; Merge Patch uses a partial object. See JSON Merge Patch.
Does this tool apply patches too?
Yes. You can generate and apply a patch to verify results.
How do I handle array inserts?
Use the add operation with a numeric index or - to append.
Is my JSON uploaded?
No. Everything runs locally in your browser.
Can I use this for API PATCH requests?
Yes. Many APIs support RFC 6902 JSON Patch for PATCH requests.
Why is my patch empty?
If the two JSON documents are identical, the diff will produce no operations.
Does order matter in patches?
Yes. Operations are applied in order, so later operations can depend on earlier ones.
Can I patch arrays safely?
Yes, but be careful with indices. Consider using test to ensure the array hasn’t changed.
Do I need to include unchanged fields?
No. JSON Patch only includes operations for fields that change.
Is JSON Patch supported by most APIs?
Many APIs support RFC 6902, but some use Merge Patch instead. Check your API documentation.
Related tools: JSON Compare, JSON Formatter, JSON Pointer, JSON Merge Patch