@lukascivil/root
Computes the difference between two JSON structures and returns an intuitive path-based delta.
Install
agr install @lukascivil/root --target claudeThis artifact does not publish files for Claude.
Document
{ "name": "root", "version": "0.0.1", "private": true, "license": "MIT", "scripts": { "show": "yarn nx show project json-difference --web", "graph": "yarn nx graph", "graph:affected": "yarn nx graph --affected", "release": "yarn nx release ${0}", "release:dry-run": "yarn nx release ${0} --dry-run", "upgrade": "yarn npm-check-updates --interactive", "claude": "yarn nx run mcp-json-diff:build --no-tui && claude" }, "devDependencies": { "@anthropic-ai/claude-code": "^2.1.117", "@chakra-ui/react": "^3.35.0", "@emotion/react": "^11.14.0", "@emotion/styled": "^11.14.1", "@modelcontextprotocol/sdk": "^1.29.0", "@nx/devkit": "22.6.5", "@nx/eslint": "22.6.5", "@nx/eslint-plugin": "22.6.5", "@nx/jest": "22.6.5", "@nx/js": "22.6.5", "@nx/vite": "22.6.5", "@nx/workspace": "22.6.5", "@types/jest": "^30.0.0", "@types/node": "^25.6.0", "@types/react": "^19.2.14", "@types/react-dom": "^19.2.3", "@typescript-eslint/eslint-plugin": "8.59.0", "@typescript-eslint/parser": "8.59.0", "@vitejs/plugin-react": "^6.0.1", "@yarnpkg/plugin-version": "^4.2.0", "copyfiles": "^2.4.1", "eslint": "^10.2.1", "eslint-config-standard-with-typescript": "^43.0.1", "eslint-plugin-import": "^2.32.0", "eslint-plugin-jest": "^29.15.2", "eslint-plugin-jsonc": "^3.1.2", "eslint-plugin-n": "^17.24.0", "eslint-plugin-prettier": "^5.5.5", "eslint-plugin-promise": "^7.2.1", "eslint-plugin-react-hooks": "^7.1.1", "eslint-plugin-react-refresh": "^0.5.2", "framer-motion": "^12.38.0", "jest": "^30.3.0", "json-difference": "1.16.2", "jsonc-eslint-parser": "^3.1.0", "lucide-react": "^1.8.0", "monaco-editor": "^0.55.1", "npm-check-updates": "^21.0.3", "nx": "22.6.5", "prettier": "^3.8.3", "react": "^19.2.5", "react-dom": "^19.2.5", "react-monaco-editor": "^0.59.0", "replace-json-property": "^1.9.0", "rollup-plugin-copy": "^3.5.0", "ts-jest": "^29.4.9", "tsx": "^4.21.0", "typescript": "6.0.3", "vite": "^8.0.9", "vite-plugin-dts": "~4.5.4", "vite-plugin-static-copy": "^4.1.0", "vite-tsconfig-paths": "^6.1.1", "zod": "^4.3.6" }, "packageManager": "yarn@4.14.1" }
Repository README
Describes lukascivil/json-difference as a whole, which may contain artifacts other than this one. Where this artifact had no useful description of its own, its summary was taken from here.
JsonDifference
Computes the difference between two JSON structures and returns an intuitive path-based delta. Fast even on large payloads.
The question it answers: given my old structure, what was changed, removed, or added to reach the new structure?
Lightweight: ๐ชถ 1.95 kB (gzip: 0.79 kB).
Live Demo
- Latest release: https://lukascivil.github.io/json-difference/
- Master (deprecated): http://jsondifference.lukascivil.com.br
Monorepo layout
This repository is an Nx monorepo containing multiple packages and apps:
| Package | Path | Published | Description |
|---|---|---|---|
json-difference | libs/json-difference | npm | Core library (ESM/CJS + browser bundle) |
json-difference-cli | libs/json-difference-cli | npm | Command-line wrapper (jd) |
mcp-json-diff | tools/mcp-json-diff | โ | MCP server exposing the lib to AI agents |
playground | apps/playground | โ | React live demo (deployed to GitHub Pages) |
example | apps/example | โ | Node scripts used as runnable usage examples |
Installation
yarn add json-difference
# Optional: terminal version
yarn add json-difference-cli
Browser (ESM via CDN):
<script type="module">
// Replace 1.16.0 with the version you want
import { getDiff } from 'https://json-difference.s3.amazonaws.com/1.16.0/json-difference-1.16.0.mjs'
</script>
Requirements: Node.js >=18.17.
Quick usage
import { getDiff } from 'json-difference'
const coffee = { color: { color1: 'black', color2: 'brown' }, special: true }
const oil = { color: { color1: 'red', color2: 'blue' }, special2: false, especial3: [{}] }
getDiff(coffee, oil)
// {
// added: [["special2", false], ["especial3", []], ["especial3/0[]", {}]],
// removed: [["special", true]],
// edited: [["color/color1", "black", "red"], ["color/color2", "brown", "blue"]]
// }
getDiff(coffee, oil, { isLodashLike: true })
// Paths become "color.color1", "especial3[0]" etc.
API
All functions are exported from json-difference.
| Function | Signature | Purpose |
|---|---|---|
getDiff | (old, new, options?) => Delta | Full delta { added, removed, edited } |
getStructPaths | (json, isLodashLike?) => StructPaths | Flatten a JSON into path โ leaf value map |
getEditedPaths | (oldPaths, newPaths) => EditedPath[] | Only paths whose value changed |
getPathsDiff | (pathsA, pathsB) => PathsDiff[] | Paths present in A but missing in B |
Options
| Option | Type | Default | Description |
|---|---|---|---|
isLodashLike | boolean | false | Switch paths from slash-notation (a/b/0[]) to lodash-style bracket notation (a.b[0]) |
Delta shape
| Operation | Tuple |
|---|---|
edited | [path, old_value, new_value] |
added | [path, new_value] |
removed | [path, old_value] |
Path markers
| Marker | Meaning |
|---|---|
__root__ | The whole object/array at the root was replaced |
@{} | Non-leaf node of type object |
@[] | Non-leaf node of type array |
Reference table of operations
| Original | Modified | Delta |
|---|---|---|
{} | [] | edited: [["__root__", {}, []]] |
[] | {} | edited: [["__root__", [], {}]] |
[{}] | [[]] | edited: [["0[]", {}, []]] |
{"a":"b"} | {"a":"c"} | edited: [["a", "b", "c"]] |
{"":""} | {"":"a"} | edited: [["", "", "a"]] |
{"":{"":""}} | {"":{"":"a"}} | edited: [["/", "", "a"]] |
[] | [{}] | added: [["0[]", {}]] |
{} | {"a":"b"} | added: [["a", "b"]] |
{"a":"b"} | {} | removed: [["a", "b"]] |
[{}] | [] | removed: [["0[]", {}]] |
Note: the output of v1.9.1 differs from v1.15.7 and later โ v1.15.7+ introduces greater accuracy in the returned paths.
CLI
# -o = original, -m = modified
jd -o "{}" -m "[]"
See json-difference-cli for details.
AI integration (MCP)
This repo ships an MCP server that exposes the library to AI agents (Claude Desktop, Claude Code, Cursor, etc.). See tools/mcp-json-diff.
Development
Install dependencies:
yarn install
Common Nx targets:
yarn nx test json-difference # run unit tests
yarn nx build json-difference # build the lib
yarn nx serve playground # run the web demo
yarn nx run example:test # run the usage scripts
yarn nx run mcp-json-diff:serve # run the MCP server (dev)
yarn nx run mcp-json-diff:test-browser # open the MCP Inspector UI
yarn nx run-many --target=type-check # type-check all projects
Workspace graph:
yarn graph # full dependency graph
yarn graph:affected # only projects affected by current changes
Contributing
To request a feature or report a bug, open an issue. PRs are welcome โ follow conventional commits, the release pipeline relies on them.
License
MIT ยฉ lukascivil
Trust
Not scanned yet. Artifacts are graded after they are crawled, so a recently discovered one may have no result for a while.
Versions
git-477c11e38ba72026-08-05