JSON structural diff
Does exactly what you think it does:
Installation
npm install -g json-diff-ext
Contribution policy
-
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.
Usage
Simple:
json-diff-ext a.json b.json
Detailed:
% json-diff-ext --help
Usage: json-diff-ext [-vjCk] first.json second.json
Arguments:
first.json Old file
second.json New file
General options:
-v, --verbose Output progress info
-C, --[no-]color Colored output
-j, --raw-json Display raw JSON encoding of the diff
-k, --keys-only Compare only the keys, ignore the differences in values
-h, --help Display this usage information
In javascript (ES5):
var jsonDiff = require('json-diff-ext')
console.log(jsonDiff.diffString({ foo: 'bar' }, { foo: 'baz' }));
// Output:
// {
// - foo: "bar"
// + foo: "baz"
// }
console.log(jsonDiff.diff({ foo: 'bar' }, { foo: 'baz' }));
// Output:
// { foo: { __old: 'bar', __new: 'baz' } }
In javascript (ES6+):
import { diffString, diff } from 'json-diff-ext';
console.log(diffString({ foo: 'bar' }, { foo: 'baz' }));
console.log(diff({ foo: 'bar' }, { foo: 'baz' }));
Features
- colorized, diff-like output
- fuzzy matching of modified array elements (when array elements are object hierarchies)
- compare only the json structure (keys), ignoring the values
- reasonable test coverage (far from 100%, though)