Start a project

Tool 118 of 194 · JSON

JSON Structural Diff & Patch

See exactly what changed between two JSON documents, path by path, and get a JSON Patch or merge patch that turns one into the other, verified before you copy it.

JSON Structural Diff & Patch at a glanceIllustration: 1, Two JSON documents; 2, processed in your browser; 3, Paths + JSON Patch.JSON Structural Diff & Patch{ }1Two JSON documents−++3Paths + JSON Patch2In yourbrowser
1 Two JSON documents 2 processed on your device 3 Paths + JSON Patch

JSON Structural Diff & Patch

Document A (before)

Document B (after)

Differences

ChangePathIn AIn B

    Patches

    JSON Patch (RFC 6902)
    Merge patch (RFC 7386)

    Both patches are applied back to A in your browser before they're shown, and the checks above say whether the result equals B.

    01

    What it does

    Compares two JSON documents path by path, ignoring key order, matches array items by key to spot moves, and writes JSON Patch and merge patch files.

    • Key order and whitespace ignored
    • Array items matched by id or another key, so reordering shows as moves
    • Content matching for arrays without keys
    • RFC 6902 JSON Patch and RFC 7386 merge patch

    02

    Private by design

    Everything happens in your browser. Nothing you type, paste or upload is sent anywhere, and it keeps working offline once the page has loaded.

    03

    What you get

    A change list, JSON Patch and merge patch, with a Copy and a Download button on every result.

    • JSON
    • JSON Patch
    • RFC 6902
    • Diff

    Why it matters

    A line diff of two JSON files is noisy: reorder the keys or reformat the file and every line changes, and a moved array item shows as one deletion and one addition far apart. What you usually want to know is which values changed, at which paths.

    This tool parses both documents and compares them as data. Objects are compared key by key in any order. Arrays of objects are matched by an identity key such as id, so a reordered list reads as moves and an edited item reads as a change, not a delete and re-add. Arrays without keys are aligned by content with the same algorithm as diff. The result is also written as an RFC 6902 JSON Patch and an RFC 7386 merge patch, and both are applied back to the first document in your browser to prove they produce the second, which catches the cases where a merge patch can't express the change.

    How it works

    1. InputAn old and a new JSON document
    2. In your browserCompared as data, arrays matched by key
    3. OutputA change list, JSON Patch and merge patch, verified

    Where it fits in a designer's workflow

    1. Plan
    2. Design
    3. Build
    4. Test
    5. Launch
    Reviewing API responses, config changes and test fixtures.

    By the numbers

    Changes between the sample's two documentsAdded: 5 paths; Removed: 1 path; Changed: 3 paths; Moved: 1 pathAdded5 pathsRemoved1 pathChanged3 pathsMoved1 path
    Found by this tool in its sample product feed: 10 changes at exact JSON Pointer paths. Reordering the products shows as one move, not a deletion and an addition. Written out, the JSON Patch is 808 bytes against 599 for the whole new document and 549 for the merge patch, so a patch pays off on large documents with small edits. Source: RFC 6902 JSON Patch; RFC 7386 merge patch.
    Show the numbers as a table
    ChangePath
    replace/version
    replace/updated
    add/store/vat
    remove/products/2
    move/products/0
    replace/products/0/price
    add/products/0/tags/1
    add/products/2
    add/features/2
    add/promo

    How to use it

    1. Paste the old document as A and the new one as B.
    2. Read the change list: each row is a JSON Pointer path with its old and new value.
    3. Set the array key if your items use something other than id, or switch to content-only matching.
    4. Copy or download the JSON Patch or merge patch; the checks say whether each one round-trips.

    FAQ

    What's the difference between JSON Patch and merge patch?

    JSON Patch (RFC 6902) is a list of operations (add, remove, replace, move) at exact paths, so it can change single array items. Merge patch (RFC 7386) is a partial document merged over the original: simpler, but arrays are replaced whole and null always means delete.

    Why does the merge patch fail the check?

    A merge patch can't set a value to null, because null means remove the key. If the new document has nulls, use the JSON Patch.

    Are 1 and 1.0 different?

    Not here. JSON numbers are compared by value, as JSON.parse reads them. The tool notes when numbers are written in a non-standard form.

    What about very large integers?

    JavaScript can't hold integers beyond 2^53 exactly, so two different IDs like 12345678901234567890 and 12345678901234567891 could look equal. The tool warns when it sees them; store such IDs as strings.

    Is my JSON uploaded?

    No. Parsing, comparing and patching all happen in your browser.

    Work with me

    Want a site that gets these right?

    I build fast, accessible websites and web apps that pass these checks from day one. Tell me about your project and I'll reply personally with honest next steps.

    All developer tools · Back to leej.uk