---
title: "JSON Patch Generator & Applier (RFC 6902) | JSON Lark"
description: "Diff two JSON documents into an RFC 6902 JSON Patch, apply a patch with clear errors, or generate and apply RFC 7396 merge patches. In your browser."
url: https://jsonlark.me/json-patch-generator/
---

Sheet 07 Patch

# JSON Patch generator

Diff two JSON documents into an RFC 6902 patch, apply a patch to a document, or do the same with RFC 7396 merge patches.

## How to use it

Pick a format, then **Generate** to compare the original with the modified document, or **Apply** to run a patch against a document. Each generated patch is applied back to the original to check that it reproduces the modified document.

- **Array diffs**: LCS leaves the common start and end of an array alone and finds the longest common subsequence of the rest, so inserting at the front is one `add`. Items changed in place are diffed recursively, so a new price inside an item is one `replace`. Index compares position by position: simpler, but larger patches.
- **JSON Pointer escaping**: Paths are JSON Pointers: `~` is written `~0` and `/` is `~1`, so the key `dims/cm` is `/dims~1cm`. In an `add`, `-` means the end of an array.
- **Test operations**: Adds a `test` of the old value before each removal or replacement, so the patch fails cleanly if the document changed meanwhile.
- **Merge Patch**: A merge patch is a plain object: members merge recursively, `null` removes a key and arrays are replaced whole. It cannot set a value to null; the status warns when that would be needed.

## Questions

**What happens when an operation fails?**

Nothing is changed. Patches are applied to a copy, all or nothing, and the status names the failing operation and why: a failed test, a missing path, or an index past the end of an array.

**Why does the generator never use move or copy?**

Add, remove and replace always describe a change exactly, while guessing moves can produce surprising patches. Move and copy are fully supported when you apply a patch.

**Are my documents uploaded?**

No. Diffing and patching run in this tab and nothing you paste leaves it. Page views are counted with Cloudflare Web Analytics, which sets no cookies and never sees your data.
