Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 99 lines (69 sloc) 3.573 kB
10fd8be @andreyvit Add README
authored
1 JSON structural diff
2 ====================
3
4 Does exactly what you think it does:
5
6 ![Screenshot](https://github.com/andreyvit/json-diff/raw/master/doc/screenshot.png)
7
8
9 Installation
10 ------------
11
12 npm install json-diff
13
14
15 Usage
16 -----
17
18 Simple:
19
20 json-diff a.json b.json
21
22 Detailed:
23
24 % json-diff --help
25 Usage: json-diff [-vjC] first.json second.json
26
27 Arguments:
28 first.json Old file
29 second.json New file
30
31 General options:
32 -v, --verbose Output progress info
33 -C, --[no-]color Colored output
34 -j, --raw-json Display raw JSON encoding of the diff
35 -h, --help Display this usage information
36
37
38 Features
39 --------
40
41 * colorized, diff-like output
42 * fuzzy matching of modified array elements (when array elements are object hierarchies)
43 * reasonable test coverage (far from 100%, though)
44
45
46 Tests
47 -----
48
49 Run:
50
d4450dc @andreyvit README: Fix 'npm test' string
authored
51 npm test
10fd8be @andreyvit Add README
authored
52
75d044d @andreyvit Setup npm run-script cov
authored
53 Test coverage report:
54
55 npm run-script cov
56
10fd8be @andreyvit Add README
authored
57 Output:
58
59 colorize
60 ✓ should return ' <value>' for a scalar value
61 ✓ should return '-<old value>', '+<new value>' for a scalar diff
62 ✓ should return '-<removed key>: <removed value>' for an object diff with a removed key
63 ✓ should return '+<added key>: <added value>' for an object diff with an added key
64 ✓ should return '+<added key>: <added stringified value>' for an object diff with an added key and a non-scalar value
65 ✓ should return ' <modified key>: <colorized diff>' for an object diff with a modified key
66 ✓ should return '+<inserted item>' for an array diff
67 ✓ should return '-<deleted item>' for an array diff
68
69 diff
70 with simple scalar values
71 ✓ should return undefined for two identical numbers
72 ✓ should return undefined for two identical strings
73 ✓ should return { __old: <old value>, __new: <new value> } object for two different numbers
74 with objects
75 ✓ should return undefined for two objects with identical contents
76 ✓ should return undefined for two object hierarchies with identical contents
77 ✓ should return { <key>__deleted: <old value> } when the second object is missing a key
78 ✓ should return { <key>__added: <new value> } when the first object is missing a key
79 ✓ should return { <key>: { __old: <old value>, __new: <new value> } } for two objects with diffent scalar values for a key
80 ✓ should return { <key>: <diff> } with a recursive diff for two objects with diffent values for a key
81 with arrays of scalars
82 ✓ should return undefined for two arrays with identical contents
83 ✓ should return [..., ['-', <removed item>], ...] for two arrays when the second array is missing a value
84 ✓ should return [..., ['+', <added item>], ...] for two arrays when the second one has an extra value
85 ✓ should return [..., ['+', <added item>]] for two arrays when the second one has an extra value at the end (edge case test)
86 with arrays of objects
87 ✓ should return undefined for two arrays with identical contents
88 ✓ should return [..., ['-', <removed item>], ...] for two arrays when the second array is missing a value
89 ✓ should return [..., ['+', <added item>], ...] for two arrays when the second array has an extra value
90 ✓ should return [..., ['~', <diff>], ...] for two arrays when an item has been modified (note: involves a crazy heuristic)
91
92 ✔ 25 tests complete (12ms)
93
94
95 License
96 -------
97
98 © Andrey Tarantsov. Distributed under the MIT license.
Something went wrong with that request. Please try again.