Skip to content

About

Compare JSON structures and values locally in your browser or terminal.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

JSON Shape Diff

CI

Compare API responses and quickly spot field, type, and value changes.

JSON Shape Diff is a dependency-free JSON comparison tool for the browser and CLI. It runs locally and does not upload or store your data.

JSON Shape Diff demo

Getting Started

Requires Node.js 22 or newer. No npm install step is needed.

npm start

Open the local URL printed by the terminal, paste two JSON documents, or click Load sample / 载入示例. The default port is 4173. If you are running multiple tools at once, choose another port:

$env:PORT = '42832'
npm start

The app is served through a local HTTP server. Opening the HTML file directly through file:// is not supported.

Features

  • Reports added fields, removed fields, and type changes.
  • Can optionally compare concrete string, number, boolean, and null values.
  • Supports objects, arrays, and scalar JSON roots.
  • Accepts pasted JSON or local files.
  • Swaps the two sides and exports Markdown or JSON reports.
  • Ignores selected JSON Pointer paths and their descendants, such as /meta/requestId or /updatedAt.
  • Clears stale reports after input changes so old exports are not reused accidentally.
  • Renders only a bounded preview in the browser while exports keep the complete report.

Comparison Semantics

Case Behavior
1 to 2 Reported only when value comparison is enabled
1 to "1" Reported as a type change
null to {} Reported as a type change
Object key order changes Not reported
A whole object is added Reported once at that object path
Array changes Compared by index; moves and IDs are not inferred

Paths use JSON Pointer. /user/id means a nested field, / means a field with an empty string as its key, and "" means the root value. Field names encode / as ~1 and ~ as ~0.

Ignored paths filter reported diff paths. If a parent object is added, removed, or changes type, that parent change is still reported even if some of its descendants would be ignored.

CLI

node bin/cli.mjs examples/before.json examples/after.json
node bin/cli.mjs examples/before.json examples/after.json --values --format json
node bin/cli.mjs examples/before.json examples/after.json --values --ignore /meta/requestId
node bin/cli.mjs examples/before.json examples/after.json -o report.md
node bin/cli.mjs examples/before.json examples/after.json --check

--ignore can be repeated and accepts JSON Pointer paths. --check is useful for automation: exit code 2 means differences were found, 0 means no differences, and 1 means input or execution failed. Output files are never overwritten.

Limits

  • Each input is limited to 5 MB.
  • Comparison stops at 100,000 nodes, 100 levels of nesting, or 5,000 reported changes.
  • The browser view renders the first 300 changes and previews up to 5,000 characters per side; exports include the full report.
  • Array insertion or movement may produce multiple positional changes.
  • JavaScript JSON parsing is used, so duplicate keys follow last-value-wins semantics and numbers use IEEE 754 precision.
  • Reports may contain source values. Share only data you are comfortable exposing.

Development

npm test

The browser app and CLI share dist/core.mjs. Tests cover structure mode, value mode, scalar roots, JSON Pointer escaping, arrays, prototype keys, invalid input, depth limits, Markdown fences, and ignored paths.

dist/ is hand-written static source and can be hosted as a static site. This repository does not publish a hosted production site.

See validation notes and contributing notes.

Roadmap

  • Match array items by a selected ID field.
  • Add wildcard ignore paths for fields repeated inside arrays.
  • Export a compact review summary for CI comments.

License

MIT

About

Compare JSON structures and values locally in your browser or terminal.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages