Gathering detailed insights and metrics for json-diff
Gathering detailed insights and metrics for json-diff
Gathering detailed insights and metrics for json-diff
Gathering detailed insights and metrics for json-diff
diff
A JavaScript text diff implementation.
json-diff-ts
Modern TypeScript JSON diff library - Zero dependencies, high performance, ESM + CommonJS support. Calculate and apply differences between JSON objects with advanced features like key-based array diffing, JSONPath support, and atomic changesets.
@types/json-diff
TypeScript definitions for json-diff
jsondiffpatch
JSON diff & patch (object and array diff, text diff, multiple output formats)
npm install json-diff
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99
Supply Chain
98.6
Quality
77.8
Maintenance
100
Vulnerability
100
License
CoffeeScript (66.56%)
JavaScript (33.44%)
Total Downloads
146,592,678
Last Day
44,550
Last Week
718,635
Last Month
3,395,796
Last Year
27,292,303
MIT License
1,194 Stars
146 Commits
136 Forks
17 Watchers
3 Branches
32 Contributors
Updated on Aug 23, 2025
Latest Version
1.0.6
Package Id
json-diff@1.0.6
Unpacked Size
38.70 kB
Size
10.12 kB
File Count
11
NPM Version
8.15.0
Node Version
16.17.0
Published on
May 15, 2023
Cumulative downloads
Total Downloads
Last Day
-14.5%
44,550
Compared to previous day
Last Week
-5.9%
718,635
Compared to previous week
Last Month
2.3%
3,395,796
Compared to previous month
Last Year
15.6%
27,292,303
Compared to previous year
3
5
Does exactly what you think it does:
1 npm install -g json-diff
This project is maintained thanks to your contributions! Please send pull requests.
I will merge any pull request that adds something useful, does not break existing things, has reasonable code quality and provides/updates tests where appropriate.
Anyone who gets a significant pull request merged gets commit access to the repository.
Simple:
1 json-diff a.json b.json
Detailed:
1 % json-diff --help 2 3 Usage: json-diff [-vCjfonskKp] first.json second.json 4 5 Arguments: 6 <first.json> Old file 7 <second.json> New file 8 9 General options: 10 -v, --verbose Output progress info 11 -C, --[no-]color Colored output 12 -j, --raw-json Display raw JSON encoding of the diff 13 -f, --full Include the equal sections of the document, not just the deltas 14 --max-elisions COUNT Max number of ...s to show in a row in "deltas" mode (before 15 collapsing them) 16 17 -o, --output-keys KEYS Always print this comma separated keys, with their value, if they are 18 part of an object with any diff 19 20 -x, --exclude-keys KEYS Exclude these comma separated keys from comparison on both files 21 22 -n, --output-new-only Output only the updated and new key/value pairs (without marking them as 23 such). If you need only the diffs from the old file, just exchange the 24 first and second json. 25 26 -s, --sort Sort primitive values in arrays before comparing 27 -k, --keys-only Compare only the keys, ignore the differences in values 28 -K, --keep-unchanged-values Instead of omitting values that are equal, output them as they are 29 -p, --precision DECIMALS Round all floating point numbers to this number of decimal places prior 30 to comparison 31 32 -h, --help Display this usage information
In javascript (ES5):
1var jsonDiff = require('json-diff'); 2 3console.log(jsonDiff.diffString({ foo: 'bar' }, { foo: 'baz' })); 4// Output: 5// { 6// - foo: "bar" 7// + foo: "baz" 8// } 9 10// As above, but without console colors 11console.log(jsonDiff.diffString({ foo: 'bar' }, { foo: 'baz' }, { color: false })); 12 13// Raw output: 14console.log(jsonDiff.diff({ foo: 'bar', b: 3 }, { foo: 'baz', b: 3 })); 15// Output: 16// { foo: { __old: 'bar', __new: 'baz' } } 17 18// Passing in the "full" option: 19console.log(jsonDiff.diff({ foo: 'bar', b: 3 }, { foo: 'baz', b: 3 }, { full: true })); 20// Output: 21// { foo: { __old: 'bar', __new: 'baz' }, b: 3 }
In javascript (ES6+):
1import { diffString, diff } from 'json-diff'; 2 3console.log(diffString({ foo: 'bar' }, { foo: 'baz' })); 4console.log(diff({ foo: 'bar' }, { foo: 'baz' }));
Unless two arrays are equal, all array elements are transformed into 2-tuple arrays:
1 json-diff.js --full --raw-json <(echo '[1,7,3]') <(echo '[1,2,3]') 2 [ [ " ", 1 ], [ "-", 7 ], [ "+", 2 ], [ " ", 3 ] ]
1 json-diff.js --full --raw-json <(echo '[1,["a","b"],4]') <(echo '[1,["a","c"],4]') 2 [ [ " ", 1 ], [ "~", [ [ " ", "a" ], [ "-", "b" ], [ "+", "c" ] ] ], [ " ", 4 ] ]
Object property values:
1 json-diff.js --full --raw-json <(echo '{"a":4}') <(echo '{"a":5}') 2 { "a": { "__old": 4, "__new": 5 } }
1 json-diff.js --full --raw-json <(echo '{"a":[4,5]}') <(echo '{"a":[4,6]}') 2 { "a": [ [ " ", 4 ], [ "-", 5 ], [ "+", 6 ] ] }
Object property keys:
1 json-diff.js --full --raw-json <(echo '{"a":[4,5]}') <(echo '{"b":[4,5]}') 2 { "a__deleted": [ 4, 5 ], "b__added": [ 4, 5 ] } 3 json-diff.js --full --raw-json <(echo '{"a":[4,5]}') <(echo '{"b":[4,6]}') 4 { "a__deleted": [ 4, 5 ], "b__added": [ 4, 6 ] }
1 json-diff.js --raw-json <(echo '{"a":4, "b":6}') <(echo '{"a":5,"b":6}') 2 { "a": { "__old": 4, "__new": 5 } }
1 json-diff.js --raw-json <(echo '[1,7,3]') <(echo '[1,2,3]') 2 [ [ " " ], [ "-", 7 ], [ "+", 2 ], [ " " ] ]
Run:
1 npm test
Output:
json-diff@0.5.3 test
coffee -c test; mocha test/*.js
colorizeToArray
✔ should return '
colorize ✔ should return a string with ANSI escapes ✔ should return a string without ANSI escapes on { color: false }
diff
with simple scalar values
✔ should return undefined for two identical numbers
✔ should return undefined for two identical strings
✔ should return { __old:
diff({sort: true}) with arrays ✔ should return undefined for two arrays with the same contents in different order
diff({keepUnchangedValues: true}) with nested object ✔ should return partial object with modified and unmodified elements in the edited scope
diff({full: true})
with simple scalar values
✔ should return the number for two identical numbers
✔ should return the string for two identical strings
✔ should return { __old:
diff({ outputKeys: foo,bar } ✔ should return keys foo and bar although they have no changes ✔ should return keys foo (with addition) and bar (with no changes) ✔ should return keys foo and bar (with addition) ✔ should return nothing as the entire object is equal, no matter that show keys has some of them ✔ should return the keys of an entire object although it has no changes
diff({keysOnly: true})
with simple scalar values
✔ should return undefined for two identical numbers
✔ should return undefined for two identical strings
✔ should return undefined object for two different numbers
with objects
✔ should return undefined for two empty objects
✔ should return undefined for two objects with identical contents
✔ should return undefined for two object hierarchies with identical contents
✔ should return {
diffString ✔ should produce the expected result for the example JSON files ✔ should produce the expected result for the example JSON files with precision set to 1 ✔ should produce the expected colored result for the example JSON files ✔ return an empty string when no diff found
diff({ outputNewOnly: true } ✔ should return only new diffs (added) ✔ should return only new diffs (changed) ✔ should return only new diffs (deleted) ✔ should return only old diffs - exchanged first and second json (added) ✔ should return only old diffs - exchanged first and second json (changed) ✔ should return only old diffs - exchanged first and second json (deleted)
107 passing (74ms)
["true"]
vs [true]
, ["0"]
vs [0]
(enabled by switching to a new difflib)© Andrey Tarantsov. Distributed under the MIT license.
No vulnerabilities found.