Skip to content

About

Compare two JSON documents in the browser. Differences are highlighted at their exact JSON path, side by side or in a unified view. Built with React, TypeScript and CodeMirror 6.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

8 Commits

Folders and files

Repository files navigation

JSON Diff Viewer

A macOS-inspired developer tool for comparing two JSON documents. It runs entirely in the browser.

JSON Viewer comparing two versions of an order in Side by Side view, dark theme: changed values highlighted in orange, an added phone number and order item in green

Features

  • Two CodeMirror 6 editors with JSON syntax highlighting, line numbers, folding, bracket matching, search, and inline error squiggles
  • Structural comparison with jsondiffpatch: added, deleted, and modified values reported at exact JSON paths ($.users[0].role), including nested objects and arrays. Key order and whitespace are ignored.
  • Side by Side (default): exactly two editors, Original and Modified. Differences are highlighted inline in your own text: green for added, red for deleted, orange for modified. Spacer rows keep shared values aligned, and the two editors scroll together.
  • Unified: one combined + / − view in place of the editors
  • Differences update automatically a moment after you stop typing. Compare (or ⌘↩) compares immediately
  • Difference summary, Previous / Next change navigation, and click-to-select changes
  • Import a .json file into either editor with its Import button or by dropping it onto that editor. Files are read locally and checked before anything is replaced: empty, malformed, non-JSON and oversized (over 50 MB) files are rejected with a message, and the editor keeps its content. The filename appears in the editor header, marked Edited once you change the text.
  • Format one editor or both, copy an editor's formatted JSON, or clear an editor. Formatting only changes whitespace: large integers, number spelling (1.50), string escapes and duplicate keys are kept exactly as written
  • Clear errors with line and column (consistent across browsers), plus a "Show" action that jumps to the error
  • Light and dark themes built on CSS variables
  • Both documents, the view mode and the theme are saved in localStorage. On first launch the editors load a sample pair of documents
  • On narrow screens the two editors stack vertically

Keyboard shortcuts

Action Shortcut
Compare ⌘↩ / Ctrl+Enter
Format both editors ⌥⇧F
Next / previous change ] / [ (outside the editors)

Scripts

npm install
npm run dev        # start the dev server
npm test           # run Vitest + React Testing Library
npm run test:watch # run tests in watch mode
npm run typecheck  # type-check only
npm run build      # type-check and build for production
npm run preview    # serve the production build locally

Structure

src/
  lib/            framework-free logic (unit tested)
    json.ts       parsing, error location, formatting
    diff.ts       jsondiffpatch delta → changes + aligned display rows
    compare.ts    parse both sides, collect errors, diff
    fileImport.ts read + validate a local JSON file
    locate.ts     JSON path → source range in the user's text
    editorDiff.ts diff → per-editor line tints, inline marks, alignment spacers
    tokenize.ts   lightweight JSON line tokenizer for the diff view
    clipboard.ts  copy to clipboard with a fallback
    samples.ts    sample documents shown on first launch
  components/     Toolbar, ThemeToggle, ViewModeSelector, EditorPanel, CodeEditor,
                  DiffSummary, DiffViewer, ChangeNavigation, ErrorMessage, Toast, Button, Icons
  hooks/          useTheme, usePersistentState
  styles/theme.css  design tokens for both themes

How the diff is rendered

jsondiffpatch produces a structural delta. diff.ts walks both documents along that delta and emits rows that are already aligned for the side-by-side view, so line numbers, trailing commas, and indentation are correct for each side. For arrays, objects are matched by an id, _id, uuid or key field when they have one (otherwise only identical objects match), so inserting an item at the top of a list reads as one addition rather than every item changing. Remaining runs of removals and insertions of the same shape are paired by position, so [1, 2, 3] → [1, 5, 3] reads as one modification at $[1]. The unified view is derived from the same rows.

For the side-by-side editors, locate.ts finds where every path sits in the text you typed. editorDiff.ts then turns each change into line tints or inline marks at those offsets, and inserts spacer blocks wherever a value present in both documents would otherwise land on different rows. CodeMirror maps the decorations through your edits until you compare again.

Credits

The app icon uses the "language-json" glyph from Brightlayer UI Icons by etn-ccis, under the MIT License.

About

Compare two JSON documents in the browser. Differences are highlighted at their exact JSON path, side by side or in a unified view. Built with React, TypeScript and CodeMirror 6.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages