- min+gzipped ~ 16KB
- browser and server (
/distfolder with bundles for UMD, commonjs, or ES modules)
- (optionally) uses google-diff-match-patch for long text diffs (diff at character level)
- smart array diffing using LCS, IMPORTANT NOTE: to match objects inside an array you must provide an
objectHashfunction (this is how objects are matched, otherwise a dumb match by position is used). For more details, check Array diff documentation
- reverse a delta
- unpatch (eg. revert object to its original state using a delta)
- simplistic, pure JSON, low footprint delta format
- multiple output formatters:
- Any modern browser and IE8+
And you can test your current browser visiting the test page.
// sample datavar country =name: "Argentina"capital: "Buenos Aires"independence: 1816 6 9unasur: true;// clone country, using dateReviver for Date objectsvar country2 = JSON;// make some changescountry2name = "Republica Argentina";country2population = 41324992;delete country2capital;var delta = jsondiffpatch;;// patch originaljsondiffpatch;// reverse diffvar reverseDelta = jsondiffpatch;// also country2 can be return to original value with: jsondiffpatch.unpatch(country2, delta);var delta2 = jsondiffpatch;// undefined => no difference
// sample datavar country =name: "Argentina"cities:name: 'Buenos Aires'population: 13028000name: 'Cordoba'population: 1430023name: 'Rosario'population: 1136286name: 'Mendoza'population: 901126name: 'San Miguel de Tucuman'population: 800000;// clone countryvar country2 = JSON;// delete Cordobacountrycities;// add La Platacountrycities;// modify Rosario, and move itvar rosario = countrycities0;rosariopopulation += 1234;countrycities;// create a configured instance, match objects by namevar diffpatcher = jsondiffpatch;var delta = diffpatcher;;
For more example cases (nested objects or arrays, long text diffs) check
If you want to understand deltas, see delta format documentation
This works for node, or in browsers if you already do bundling on your app
npm install jsondiffpatch
var jsondiffpatch = ;
In a browser, you could load directly a bundle in
var jsondiffpatch =;
To see formatters in action check the Live Demo.
For more details check Formatters documentation
# diff two json files, colored output (using chalk lib)./node_modules/.bin/jsondiffpatch ./left.json ./right.json# or install globallynpm install -g jsondiffpatchjsondiffpatch ./demo/left.json ./demo/right.json
reverse() functions are implemented using Pipes & Filters pattern, making it extremely customizable by adding or replacing filters on a pipe.
Check Plugins documentation for details.