PrettyJSON Logo
PrettyJSON

Instantly clean, validate, and inspect web payloads

JSON Compare
Original JSON
Modified JSON
RFC 8259 Compliant & 100% Client-Side

JSON Compare Online — Side-by-Side JSON Diff & Comparison

Compare two JSON payloads side-by-side with semantic object diffing and LCS array alignment. Instantly detect added, removed, and modified keys — 100% client-side, zero data uploaded.

Private & Offline Ready

Every tool runs in your browser, so the JSON you paste never leaves your device.

Works Instantly, Even Offline

Formatting, minifying, repairing, and the tree view all run on your device, so there are no uploads to wait on.

Exact Error Line & Column

Syntax errors like unescaped quotes and trailing commas are flagged with their exact line and column.

Semantic JSON Diffing Algorithms & LCS Array Sequence Alignment

How PrettyJSON compares two JSON payloads using RFC 8259 compliant key-order-agnostic object comparison and Longest Common Subsequence array alignment.

1. Semantic Object Diffing (RFC 8259 §4 Compliant)

RFC 8259 §4 explicitly states that JSON objects are unordered collections of name/value pairs — the order in which keys appear carries zero semantic meaning. This means {"a":1,"b":2} and {"b":2,"a":1} are logically identical documents. Naive diff tools that compare keys by insertion order will incorrectly flag these as different, generating false positive noise that wastes developer time. PrettyJSON's semantic diff engine builds key-set unions from both objects and compares values by key name lookup, not positional iteration. Only genuine additions (keys present only in the modified object), removals (keys present only in the original), and value modifications are reported. This approach guarantees that re-serialized API responses, database exports with non-deterministic key ordering, and shuffled configuration files produce zero spurious diff entries.

Technical Highlights

  • Objects are compared by key-set union lookup, never by insertion order position.
  • Reordered keys produce zero diff entries — fully RFC 8259 §4 compliant.
  • Only genuine additions, removals, and value changes are reported.

2. Smart Array Diffing via LCS Sequence Alignment

The most common pitfall in JSON comparison tools is naive index-by-index array diffing. If one element is inserted at the beginning of an array, every subsequent index pair mismatches, flooding the diff with false "modified" entries. PrettyJSON solves this using a Longest Common Subsequence (LCS) dynamic programming algorithm. The LCS algorithm computes the longest ordered subsequence of elements common to both arrays using deep equality matching. By walking the LCS alignment table, the diff engine precisely classifies each element as unchanged (present in both arrays), added (only in modified), or removed (only in original). For example, comparing ["a","b","c","d"] vs ["a","x","b","c","d"] correctly identifies a single insertion of "x" at index 1, instead of flagging 4 cascading false changes. The LCS implementation uses standard O(m×n) dynamic programming, which handles arrays of several hundred elements instantly in-browser.

LCS Array Diff vs Naive Index Diff
Original: ["a", "b", "c", "d"]
Modified: ["a", "x", "b", "c", "d"]

--- Naive Index Diff (INCORRECT) ---
[1] Modified: "b" → "x"
[2] Modified: "c" → "b"
[3] Modified: "d" → "c"
[4] Added: "d"
→ 4 changes reported (3 are false positives!)

--- LCS Smart Diff (CORRECT) ---
[1] Added: "x"
→ 1 change reported (accurate!)
Explanation: LCS sequence alignment detects the actual insertion point without cascading false modifications across the rest of the array.

3. Recursive Composition & Practical Use Cases

PrettyJSON's diff engine composes the semantic object diff and LCS array diff algorithms recursively. At each node in the JSON tree, the engine dispatches to the appropriate strategy: object nodes use key-set union comparison, array nodes use LCS alignment, and primitive nodes use direct value and type equality checks. Type mismatches (e.g., a key that was a string in the original but became an array in the modified) are reported as modifications with both old and new values displayed. This recursive composition naturally handles deeply nested structures like GraphQL responses, Elasticsearch query results, and Kubernetes manifests. Common use cases include comparing API response snapshots before and after code changes, validating configuration drift between staging and production environments, and auditing schema migrations in database export files.

Technical Highlights

  • Recursive dispatch: objects → semantic diff, arrays → LCS, primitives → equality.
  • Type mismatches are clearly reported with both old and new values.
  • Ideal for API snapshot testing, config drift detection, and schema migration auditing.

Frequently Asked Questions

Common questions and expert answers regarding this tool.

How does PrettyJSON compare two JSON payloads?

PrettyJSON uses a semantic diff engine that compares objects by key name (ignoring key order per RFC 8259) and arrays using LCS (Longest Common Subsequence) sequence alignment. This produces accurate results without false positives from key reordering or array index shifting.

Does JSON Compare detect array insertions and deletions accurately?

Yes. Unlike basic tools that compare arrays index-by-index (where inserting one element cascades false changes), PrettyJSON uses LCS alignment to precisely identify which elements were inserted, deleted, or modified without affecting unrelated elements.

Are objects with reordered keys treated as different?

No. Per RFC 8259 §4, JSON objects are unordered collections. PrettyJSON treats {"a":1,"b":2} and {"b":2,"a":1} as identical, reporting zero differences. Only actual value changes, added keys, or removed keys are flagged.