{"id":13526299,"url":"https://github.com/andreyvit/json-diff","last_synced_at":"2025-05-14T03:07:24.596Z","repository":{"id":3029795,"uuid":"4049952","full_name":"andreyvit/json-diff","owner":"andreyvit","description":"Structural diff for JSON files","archived":false,"fork":false,"pushed_at":"2024-04-10T14:05:29.000Z","size":584,"stargazers_count":1170,"open_issues_count":32,"forks_count":135,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-04-10T10:46:08.353Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"CoffeeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andreyvit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE-MIT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-04-17T07:28:05.000Z","updated_at":"2025-04-08T15:42:48.000Z","dependencies_parsed_at":"2024-06-05T03:57:07.367Z","dependency_job_id":"af2a9b5b-5f71-4fa0-9cb0-ced1deb3a7f2","html_url":"https://github.com/andreyvit/json-diff","commit_stats":{"total_commits":121,"total_committers":30,"mean_commits":4.033333333333333,"dds":0.6611570247933884,"last_synced_commit":"d5c35c40ab67796b93a83c3bc87b6f18fa1e6c35"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreyvit%2Fjson-diff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreyvit%2Fjson-diff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreyvit%2Fjson-diff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreyvit%2Fjson-diff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andreyvit","download_url":"https://codeload.github.com/andreyvit/json-diff/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248281415,"owners_count":21077423,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T06:01:27.662Z","updated_at":"2025-04-10T19:32:08.606Z","avatar_url":"https://github.com/andreyvit.png","language":"CoffeeScript","readme":"# JSON structural diff\n\nDoes exactly what you think it does:\n\n![Screenshot](https://github.com/andreyvit/json-diff/raw/master/doc/screenshot.png)\n\n## Installation\n\n```sh\n    npm install -g json-diff\n```\n\n## Contribution policy\n\n1. This project is maintained thanks to your contributions! Please send pull requests.\n\n2. 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.\n\n3. Anyone who gets a significant pull request merged gets commit access to the repository.\n\n## Usage\n\nSimple:\n\n```sh\n    json-diff a.json b.json\n```\n\nDetailed:\n\n```sh\n    % json-diff --help\n\n    Usage: json-diff [-vCjfonskKp] first.json second.json\n\n    Arguments:\n    \u003cfirst.json\u003e          Old file\n    \u003csecond.json\u003e         New file\n\n    General options:\n    -v, --verbose         Output progress info\n    -C, --[no-]color      Colored output\n    -j, --raw-json        Display raw JSON encoding of the diff\n    -f, --full            Include the equal sections of the document, not just the deltas\n        --max-elisions COUNT  Max number of ...s to show in a row in \"deltas\" mode (before\n                                collapsing them)\n\n    -o, --output-keys KEYS  Always print this comma separated keys, with their value, if they are\n                            part of an object with any diff\n\n    -x, --exclude-keys KEYS  Exclude these comma separated keys from comparison on both files\n\n    -n, --output-new-only   Output only the updated and new key/value pairs (without marking them as\n                            such). If you need only the diffs from the old file, just exchange the\n                            first and second json.\n\n    -s, --sort            Sort primitive values in arrays before comparing\n    -k, --keys-only       Compare only the keys, ignore the differences in values\n    -K, --keep-unchanged-values   Instead of omitting values that are equal, output them as they are\n    -p, --precision DECIMALS  Round all floating point numbers to this number of decimal places prior\n                                to comparison\n\n    -h, --help            Display this usage information\n```\n\nIn javascript (ES5):\n\n```js\nvar jsonDiff = require('json-diff');\n\nconsole.log(jsonDiff.diffString({ foo: 'bar' }, { foo: 'baz' }));\n// Output:\n//  {\n// -  foo: \"bar\"\n// +  foo: \"baz\"\n//  }\n\n// As above, but without console colors\nconsole.log(jsonDiff.diffString({ foo: 'bar' }, { foo: 'baz' }, { color: false }));\n\n// Raw output:\nconsole.log(jsonDiff.diff({ foo: 'bar', b: 3 }, { foo: 'baz', b: 3 }));\n// Output:\n// { foo: { __old: 'bar', __new: 'baz' } }\n\n// Passing in the \"full\" option:\nconsole.log(jsonDiff.diff({ foo: 'bar', b: 3 }, { foo: 'baz', b: 3 }, { full: true }));\n// Output:\n// { foo: { __old: 'bar', __new: 'baz' }, b: 3 }\n```\n\nIn javascript (ES6+):\n\n```js\nimport { diffString, diff } from 'json-diff';\n\nconsole.log(diffString({ foo: 'bar' }, { foo: 'baz' }));\nconsole.log(diff({ foo: 'bar' }, { foo: 'baz' }));\n```\n\n## Features\n\n- colorized, diff-like output\n- fuzzy matching of modified array elements (when array elements are object hierarchies)\n- \"keysOnly\" option to compare only the json structure (keys), ignoring the values\n- \"full\" option to output the entire json tree, not just the deltas\n- \"outputKeys\" option to always output the given keys for an object that has differences\n- reasonable test coverage (far from 100%, though)\n\n## Output Language in Raw-json mode (\"full\" mode)\n\n### ARRAYS\n\nUnless two arrays are equal, all array elements are transformed into 2-tuple arrays:\n\n- The first element is a one character string denoting the equality ('+', '-', '~', ' ')\n- The second element is the old (-), new (+), altered sub-object (~), or unchanged (' ') value\n\n```sh\n    json-diff.js --full --raw-json \u003c(echo '[1,7,3]') \u003c(echo '[1,2,3]')\n         [ [ \" \", 1 ], [ \"-\", 7 ], [ \"+\", 2 ], [ \" \", 3 ] ]\n```\n\n```sh\n    json-diff.js --full --raw-json \u003c(echo '[1,[\"a\",\"b\"],4]') \u003c(echo '[1,[\"a\",\"c\"],4]')\n         [ [ \" \", 1 ], [ \"~\", [ [ \" \", \"a\" ], [ \"-\", \"b\" ], [ \"+\", \"c\" ] ] ], [ \" \", 4 ] ]\n```\n\n- If two arrays are equal, they are left as is.\n\n### OBJECTS\n\n**Object property values:**\n\n- If equal, they are left as is\n- Unequal scalar values are replaced by an object containing the old and new value:\n\n```sh\n    json-diff.js --full  --raw-json \u003c(echo '{\"a\":4}') \u003c(echo '{\"a\":5}')\n        { \"a\": { \"__old\": 4, \"__new\": 5 } }\n```\n\n- Unequal arrays and objects are replaced by their diff:\n\n```sh\n    json-diff.js --full  --raw-json \u003c(echo '{\"a\":[4,5]}') \u003c(echo '{\"a\":[4,6]}')\n        { \"a\": [ [ \" \", 4 ], [ \"-\", 5 ], [ \"+\", 6 ] ] }\n```\n\n**Object property keys:**\n\n- Object keys that are deleted or added between two objects are marked as such:\n\n```sh\n    json-diff.js --full  --raw-json \u003c(echo '{\"a\":[4,5]}') \u003c(echo '{\"b\":[4,5]}')\n        { \"a__deleted\": [ 4, 5 ], \"b__added\": [ 4, 5 ] }\n    json-diff.js --full  --raw-json \u003c(echo '{\"a\":[4,5]}') \u003c(echo '{\"b\":[4,6]}')\n        { \"a__deleted\": [ 4, 5 ], \"b__added\": [ 4, 6 ] }\n```\n\n## Non-full mode\n\n- In regular, delta-only (non-\"full\") mode, equal properties and values are omitted:\n\n```sh\n    json-diff.js --raw-json \u003c(echo '{\"a\":4, \"b\":6}') \u003c(echo '{\"a\":5,\"b\":6}')\n        { \"a\": { \"__old\": 4, \"__new\": 5 } }\n```\n\n- Equal array elements are represented by a one-tuple containing only a space \" \":\n\n```sh\n    json-diff.js --raw-json \u003c(echo '[1,7,3]') \u003c(echo '[1,2,3]')\n        [ [ \" \" ], [ \"-\", 7 ], [ \"+\", 2 ], [ \" \" ] ]\n```\n\n## Tests\n\nRun:\n\n```sh\n    npm test\n```\n\nOutput:\n\u003cdetails\u003e\n  \u003csummary\u003e\u003cb\u003e Open to View Test Output 🔽 \u003c/b\u003e\u003c/summary\u003e\n\n    json-diff@0.5.3 test\n    coffee -c test; mocha test/*.js\n\n  colorizeToArray\n    ✔ should return ' \u003cvalue\u003e' for a scalar value\n    ✔ should return ' \u003cvalue\u003e' for 'null' value\n    ✔ should return ' \u003cvalue\u003e' for 'false' value\n    ✔ should return '-\u003cold value\u003e', '+\u003cnew value\u003e' for a scalar diff\n    ✔ should return '-\u003cold value\u003e', '+\u003cnew value\u003e' for 'null' and 'false' diff\n    ✔ should return '-\u003cremoved key\u003e: \u003cremoved value\u003e' for an object diff with a removed key\n    ✔ should return '+\u003cadded key\u003e: \u003cadded value\u003e' for an object diff with an added key\n    ✔ should return '+\u003cadded key\u003e: \u003cadded value\u003e' for an object diff with an added key with 'null' value\n    ✔ should return '+\u003cadded key\u003e: \u003cadded value\u003e' for an object diff with an added key with 'false' value\n    ✔ should return '+\u003cadded key\u003e: \u003cadded stringified value\u003e' for an object diff with an added key and a non-scalar value\n    ✔ should return ' \u003cmodified key\u003e: \u003ccolorized diff\u003e' for an object diff with a modified key\n    ✔ should return '+\u003cinserted item\u003e' for an array diff\n    ✔ should return '-\u003cdeleted item\u003e' for an array diff\n    ✔ should handle an array diff with subobject diff\n    ✔ should collapse long sequences of identical subobjects into one '...'\n\n  colorize\n    ✔ should return a string with ANSI escapes\n    ✔ should return a string without ANSI escapes on { color: false }\n\n  diff\n    with simple scalar values\n      ✔ should return undefined for two identical numbers\n      ✔ should return undefined for two identical strings\n      ✔ should return { __old: \u003cold value\u003e, __new: \u003cnew value\u003e } object for two different numbers\n    with objects\n      ✔ should return undefined for two empty objects\n      ✔ should return undefined for two objects with identical contents\n      ✔ should return undefined for two object hierarchies with identical contents\n      ✔ should return { \u003ckey\u003e__deleted: \u003cold value\u003e } when the second object is missing a key\n      ✔ should return { \u003ckey\u003e__added: \u003cnew value\u003e } when the first object is missing a key\n      ✔ should return { \u003ckey\u003e: { __old: \u003cold value\u003e, __new: \u003cnew value\u003e } } for two objects with different scalar values for a key\n      ✔ should return { \u003ckey\u003e: \u003cdiff\u003e } with a recursive diff for two objects with different values for a key\n    with arrays of scalars\n      ✔ should return undefined for two arrays with identical contents\n      ✔ should return [..., ['-', \u003cremoved item\u003e], ...] for two arrays when the second array is missing a value\n      ✔ should return [..., ['+', \u003cadded item\u003e], ...] for two arrays when the second one has an extra value\n      ✔ should return [..., ['+', \u003cadded item\u003e]] for two arrays when the second one has an extra value at the end (edge case test)\n    with arrays of objects\n      ✔ should return undefined for two arrays with identical contents\n      ✔ should return undefined for two arrays with identical, empty object contents\n      ✔ should return undefined for two arrays with identical, empty array contents\n      ✔ should return undefined for two arrays with identical array contents including 'null'\n      ✔ should return undefined for two arrays with identical, repeated contents\n      ✔ should return [..., ['-', \u003cremoved item\u003e], ...] for two arrays when the second array is missing a value\n      ✔ should return [..., ['+', \u003cadded item\u003e], ...] for two arrays when the second array has an extra value\n      ✔ should return [['+', \u003cadded item\u003e], ..., ['+', \u003cadded item\u003e]] for two arrays containing objects of 3 or more properties when the second array has extra values (fixes issue #57)\n      ✔ should return [..., ['+', \u003cadded item\u003e], ...] for two arrays when the second array has a new but nearly identical object added\n      ✔ should return [..., ['~', \u003cdiff\u003e], ...] for two arrays when an item has been modified\n    with reported bugs\n      ✔ should handle type mismatch during scalarize\n      ✔ should handle mixed scalars and non-scalars in scalarize\n\n  diff({sort: true})\n    with arrays\n      ✔ should return undefined for two arrays with the same contents in different order\n\n  diff({keepUnchangedValues: true})\n    with nested object\n      ✔ should return partial object with modified and unmodified elements in the edited scope\n\n  diff({full: true})\n    with simple scalar values\n      ✔ should return the number for two identical numbers\n      ✔ should return the string for two identical strings\n      ✔ should return { __old: \u003cold value\u003e, __new: \u003cnew value\u003e } object for two different numbers\n    with objects\n      ✔ should return an empty object for two empty objects\n      ✔ should return the object for two objects with identical contents\n      ✔ should return the object for two object hierarchies with identical contents\n      ✔ should return { \u003ckey\u003e__deleted: \u003cold value\u003e, \u003cremaining properties\u003e} when the second object is missing a key\n      ✔ should return { \u003ckey\u003e__added: \u003cnew value\u003e, \u003cremaining properties\u003e } when the first object is missing a key\n      ✔ should return { \u003ckey\u003e: { __old: \u003cold value\u003e, __new: \u003cnew value\u003e } } for two objects with different scalar values for a key\n      ✔ should return { \u003ckey\u003e: \u003cdiff\u003e, \u003cequal properties\u003e } with a recursive diff for two objects with different values for a key\n      ✔ should return { \u003ckey\u003e: \u003cdiff\u003e, \u003cequal properties\u003e } with a recursive diff for two objects with different values for a key\n    with arrays of scalars\n      ✔ should return an array showing no changes for any element for two arrays with identical contents\n      ✔ should return [[' ', \u003cunchanged item\u003e], ['-', \u003cremoved item\u003e], [' ', \u003cunchanged item\u003e]] for two arrays when the second array is missing a value\n      ✔ should return [' ', \u003cunchanged item\u003e], ['+', \u003cadded item\u003e], [' ', \u003cunchanged item\u003e]] for two arrays when the second one has an extra value\n      ✔ should return [' ', \u003cunchanged item\u003es], ['+', \u003cadded item\u003e]] for two arrays when the second one has an extra value at the end (edge case test)\n    with arrays of objects\n      ✔ should return an array of unchanged elements for two arrays with identical contents\n      ✔ should return an array with an unchanged element for two arrays with identical, empty object contents\n      ✔ should return an array with an unchanged element for two arrays with identical, empty array contents\n      ✔ should return an array of unchanged elements for two arrays with identical array contents including 'null'\n      ✔ should return an array of unchanged elements for two arrays with identical, repeated contents\n      ✔ should return [[' ', \u003cunchanged item\u003e], ['-', \u003cremoved item\u003e], [' ', \u003cunchanged item\u003e]] for two arrays when the second array is missing a value\n      ✔ should return [[' ', \u003cunchanged item\u003e], ['+', \u003cadded item\u003e], [' ', \u003cunchanged item\u003e]] for two arrays when the second array has an extra value\n      ✔ should return [[' ', \u003cunchanged item\u003e], ['+', \u003cadded item\u003e], [' ', \u003cunchanged item\u003e]] for two arrays when the second array has a new but nearly identical object added\n      ✔ should return [[' ', \u003cunchanged item\u003e], ['~', \u003cdiff\u003e], [' ', \u003cunchanged item\u003e]] for two arrays when an item has been modified\n\n  diff({ outputKeys: foo,bar }\n    ✔ should return keys foo and bar although they have no changes\n    ✔ should return keys foo (with addition) and bar (with no changes) \n    ✔ should return keys foo and bar (with addition) \n    ✔ should return nothing as the entire object is equal, no matter that show keys has some of them\n    ✔ should return the keys of an entire object although it has no changes \n\n  diff({keysOnly: true})\n    with simple scalar values\n      ✔ should return undefined for two identical numbers\n      ✔ should return undefined for two identical strings\n      ✔ should return undefined object for two different numbers\n    with objects\n      ✔ should return undefined for two empty objects\n      ✔ should return undefined for two objects with identical contents\n      ✔ should return undefined for two object hierarchies with identical contents\n      ✔ should return { \u003ckey\u003e__deleted: \u003cold value\u003e } when the second object is missing a key\n      ✔ should return { \u003ckey\u003e__added: \u003cnew value\u003e } when the first object is missing a key\n      ✔ should return undefined for two objects with different scalar values for a key\n      ✔ should return undefined with a recursive diff for two objects with different values for a key\n      ✔ should return { \u003ckey\u003e: \u003cdiff\u003e } with a recursive diff when second object is missing a key and two objects with different values for a key\n    with arrays of scalars\n      ✔ should return undefined for two arrays with identical contents\n      ✔ should return undefined for two arrays with when an item has been modified\n      ✔ should return [..., ['-', \u003cremoved item\u003e], ...] for two arrays when the second array is missing a value\n      ✔ should return [..., ['+', \u003cadded item\u003e], ...] for two arrays when the second one has an extra value\n      ✔ should return [..., ['+', \u003cadded item\u003e]] for two arrays when the second one has an extra value at the end (edge case test)\n    with arrays of objects\n      ✔ should return undefined for two arrays with identical contents\n      ✔ should return undefined for two arrays with identical, empty object contents\n      ✔ should return undefined for two arrays with identical, empty array contents\n      ✔ should return undefined for two arrays with identical, repeated contents\n      ✔ should return [..., ['-', \u003cremoved item\u003e], ...] for two arrays when the second array is missing a value\n      ✔ should return [..., ['+', \u003cadded item\u003e], ...] for two arrays when the second array has an extra value\n      ✔ should return [..., ['~', \u003cdiff\u003e], ...] for two arrays when an item has been modified\n\n  diffString\n    ✔ should produce the expected result for the example JSON files\n    ✔ should produce the expected result for the example JSON files with precision set to 1\n    ✔ should produce the expected colored result for the example JSON files\n    ✔ return an empty string when no diff found\n\n  diff({ outputNewOnly: true }\n    ✔ should return only new diffs (added)\n    ✔ should return only new diffs (changed)\n    ✔ should return only new diffs (deleted)\n    ✔ should return only old diffs - exchanged first and second json (added)\n    ✔ should return only old diffs - exchanged first and second json (changed)\n    ✔ should return only old diffs - exchanged first and second json (deleted)\n\n\n  107 passing (74ms)\n\u003c/details\u003e\n\n## Change Log\n- 1.0.6 Comment out another debugging output.\n- 1.0.5 Comment out debugging output(!)\n- 1.0.4 Fix typo that broke -o/--output-keys\n- 1.0.3 Change from cli-color to colors to reduce package size.\n- 1.0.2 Add colorize and colorizeToCallback to module exports (Fix bug #103)\n- 1.0.1 Bug fixes: Properly compare date objects; properly exclude keys with -x; improve README readability.\n- 1.0.0 Properly distinguish list elements with identical strings of different types e.g. `[\"true\"]` vs `[true]`, `[\"0\"]` vs `[0]` (enabled by switching to a new difflib)\n- 0.10.0 Add --exclude-keys\n- 0.9.1 Fix bug #88\n- 0.9.0 Add --output-new-only option\n- 0.8.0 Add --keep-unchanged-values option\n- 0.7.4 Fix bug #76\n- 0.7.3 Revert use of ?? operator in 0.7.2 (which caused a breaking change)\n- 0.7.2 Add --maxElisions and --precision options.\n- 0.7.1 Add --output-keys option.\n- 0.7.0 Add --sort option.\n- 0.6.3 Fix ticket #68.\n- 0.6.2 Provide examples of setting mode from code.\n- 0.6.1 Return exit code 0. Update cli-color to the latest version.\n- 0.6.0 Convert project code to ES6.\n- 0.5.5 Fix bug in scalarize fuzzy compare logic.\n- 0.4.0 Add --keys-only feature.\n\n## License\n\n© Andrey Tarantsov. Distributed under the MIT license.\n","funding_links":[],"categories":["Repository","CoffeeScript"],"sub_categories":["Object / JSON / JSON Schema"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreyvit%2Fjson-diff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreyvit%2Fjson-diff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreyvit%2Fjson-diff/lists"}