{"name":"jsondiffpatch","version":"0.7.6","author":{"name":"Benjamin Eidelman","email":"beneidel@gmail.com"},"description":"JSON diff & patch (object and array diff, text diff, multiple output formats)","contributors":[{"name":"Benjamin Eidelman","email":"beneidel@gmail.com"}],"type":"module","sideEffects":["*.css"],"main":"./lib/index.js","types":"./lib/index.d.ts","exports":{".":"./lib/index.js","./with-text-diffs":"./lib/with-text-diffs.js","./formatters/*":"./lib/formatters/*.js","./formatters/styles/*.css":"./lib/formatters/styles/*.css"},"bin":{"jsondiffpatch":"bin/jsondiffpatch.js"},"scripts":{"build":"tsc && ncp ./src/formatters/styles/ ./lib/formatters/styles/","type-check":"tsc --noEmit","lint":"biome check --error-on-warnings .","test":"vitest --coverage","prepack":"npm run build && cp ../../MIT-LICENSE.txt . && cp ../../README.md .","prepublishOnly":"npm run test && npm run lint"},"repository":{"type":"git","url":"git+https://github.com/benjamine/jsondiffpatch.git"},"keywords":["json","diff","patch"],"dependencies":{"@dmsnell/diff-match-patch":"^1.1.0"},"devDependencies":{"@types/node":"^25.6.1","@vitest/coverage-v8":"^3.0.9","ncp":"^2.0.0","tslib":"^2.6.2","typescript":"^5.8.2","vitest":"^3.0.9"},"license":"MIT","engines":{"node":"^18.0.0 || >=20.0.0"},"homepage":"https://github.com/benjamine/jsondiffpatch","gitHead":"a60db8a232f92ee4b987c14f43f77402885d1a5a","_id":"jsondiffpatch@0.7.6","bugs":{"url":"https://github.com/benjamine/jsondiffpatch/issues"},"_nodeVersion":"24.14.1","_npmVersion":"11.11.0","dist":{"integrity":"sha512-zE9+AXFq+MkTolDor2Cw1nJzLC0aleqPkYf52Kb4Kn4mJcka/gFHpGI2JBVEJCfWOvBl0OoxZS+wuLdislQcqg==","shasum":"5b71221911ef1bc2725a42da66a4aea83ec7220a","tarball":"http://registry-npm.ywwl.com/jsondiffpatch/download/jsondiffpatch-0.7.6.tgz","fileCount":57,"unpackedSize":163006,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/jsondiffpatch@0.7.6","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCZAaqRn6bJImAOwyxL2JvELYRqIxlZAEzTRw4FnQIFNwIge/0Lr7vdE5QNPlAlEGHTsZNteh+gzP2fylQdWlh+Po0="}],"size":35446,"noattachment":false,"key":"/jsondiffpatch/-/jsondiffpatch-0.7.6.tgz"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:af41580d-eb77-47d9-9eee-d46810ecd190"}},"directories":{},"maintainers":[{"name":"beneidel","email":"beneidel@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/jsondiffpatch_0.7.6_1778799386986_0.7269611777114482"},"_hasShrinkwrap":false,"readme":"<p align=\"center\">\n  <img src=\"demos/html-demo/logo.svg\" width=\"48px\" align=\"center\" alt=\"jsondiffpatch logo\" />\n  <h1 align=\"center\">jsondiffpatch</h1>\n  <p align=\"center\">\n    <a href=\"https://jsondiffpatch.com\">jsondiffpatch.com</a>\n    <br/>\n    Diff & patch JavaScript objects\n  </p>\n</p>\n\n<!--- badges -->\n<p align=\"center\">\n  <a href=\"https://github.com/benjamine/jsondiffpatch/actions?query=branch%3Amaster\"><img src=\"https://github.com/benjamine/jsondiffpatch/actions/workflows/CI.yml/badge.svg?event=push&branch=master\" alt=\"JsonDiffPatch CI status\" /></a>\n  <a href=\"https://twitter.com/beneidel\" rel=\"nofollow\"><img src=\"https://img.shields.io/badge/created%20by-@beneidel-BACABA.svg\" alt=\"Created by Benjamin Eidelman\"></a>\n  <a href=\"https://opensource.org/licenses/MIT\" rel=\"nofollow\"><img src=\"https://img.shields.io/github/license/benjamine/jsondiffpatch\" alt=\"License\"></a>\n  <a href=\"https://www.npmjs.com/package/jsondiffpatch\" rel=\"nofollow\"><img src=\"https://img.shields.io/npm/dw/jsondiffpatch.svg\" alt=\"npm\"></a>\n  <a href=\"https://github.com/benjamine/jsondiffpatch\" rel=\"nofollow\"><img src=\"https://img.shields.io/github/stars/benjamine/jsondiffpatch\" alt=\"stars\"></a>\n</p>\n\n---\n\n## **[Live Demo](https://jsondiffpatch.com)**\n\n- min+gzipped ~ 16KB\n- browser and server (ESM-only)\n- deep diff, use delta to patch\n- smart array diffing using [LCS](http://en.wikipedia.org/wiki/Longest_common_subsequence_problem), **_IMPORTANT NOTE:_** to match objects inside an array you must provide an `objectHash` function (this is how objects are matched, otherwise a dumb match by position is used). For more details, check [Array diff documentation](docs/arrays.md)\n- (optionally) text diffing of long strings powered by [google-diff-match-patch](http://code.google.com/p/google-diff-match-patch/) (diff at character level)\n- reverse a delta, unpatch (eg. revert object to its original state using a delta)\n- multiple output formats:\n  - pure JSON, low footprint [delta format](docs/deltas.md)\n  - <span style=\"background-color: #bbffbb; color: black;\">visual</span> <span style=\"background-color: #ffbbbb; color:black; text-decoration: line-through\">diff</span> (html), see [demo](https://jsondiffpatch.com)\n  - annotated JSON (html), to help explain the delta format with annotations\n  - JSON Patch ([RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902)), can generate patches, and also apply them\n  - console (colored), try running `./node_modules/.bin/jsondiffpatch left.json right.json`\n  - write your own! check [Formatters documentation](docs/formatters.md)\n- BONUS: `jsondiffpatch.clone(obj)` (deep clone)\n\n## Supported platforms\n\n- Any browser that [supports ES6](https://caniuse.com/es6)\n- Node.js 18, 20+\n\n## Usage\n\non your terminal:\n\n```sh\nnpx jsondiffpatch --help\n```\n\n![console_demo!](docs/demo/consoledemo.png)\n\nor as a library:\n\n```ts\n// sample data\nconst country = {\n  name: 'Argentina',\n  capital: 'Buenos Aires',\n  independence: new Date(1816, 6, 9),\n};\n\n// clone country, using dateReviver for Date objects\nconst country2 = JSON.parse(JSON.stringify(country), jsondiffpatch.dateReviver);\n\n// make some changes\ncountry2.name = 'Republica Argentina';\ncountry2.population = 41324992;\ndelete country2.capital;\n\nconst delta = jsondiffpatch.diff(country, country2);\n\nassertSame(delta, {\n  name: ['Argentina', 'Republica Argentina'], // old value, new value\n  population: ['41324992'], // new value\n  capital: ['Buenos Aires', 0, 0], // deleted\n});\n\n// patch original\njsondiffpatch.patch(country, delta);\n\n// reverse diff\nconst reverseDelta = jsondiffpatch.reverse(delta);\n// also country2 can be return to original value with: jsondiffpatch.unpatch(country2, delta);\n\nconst delta2 = jsondiffpatch.diff(country, country2);\nassert(delta2 === undefined);\n// undefined => no difference\n```\n\nArray diffing:\n\n```ts\n// sample data\nconst country = {\n  name: 'Argentina',\n  cities: [\n    {\n      name: 'Buenos Aires',\n      population: 13028000,\n    },\n    {\n      name: 'Cordoba',\n      population: 1430023,\n    },\n    {\n      name: 'Rosario',\n      population: 1136286,\n    },\n    {\n      name: 'Mendoza',\n      population: 901126,\n    },\n    {\n      name: 'San Miguel de Tucuman',\n      population: 800000,\n    },\n  ],\n};\n\n// clone country\nconst country2 = JSON.parse(JSON.stringify(country));\n\n// delete Cordoba\ncountry.cities.splice(1, 1);\n\n// add La Plata\ncountry.cities.splice(4, 0, {\n  name: 'La Plata',\n});\n\n// modify Rosario, and move it\nconst rosario = country.cities.splice(1, 1)[0];\nrosario.population += 1234;\ncountry.cities.push(rosario);\n\n// create a configured instance, match objects by name\nconst diffpatcher = jsondiffpatch.create({\n  objectHash: function (obj) {\n    return obj.name;\n  },\n});\n\nconst delta = diffpatcher.diff(country, country2);\n\nassertSame(delta, {\n  cities: {\n    _t: 'a', // indicates this node is an array (not an object)\n    1: [\n      // inserted at index 1\n      {\n        name: 'Cordoba',\n        population: 1430023,\n      },\n    ],\n    2: {\n      // population modified at index 2 (Rosario)\n      population: [1137520, 1136286],\n    },\n    _3: [\n      // removed from index 3\n      {\n        name: 'La Plata',\n      },\n      0,\n      0,\n    ],\n    _4: [\n      // move from index 4 to index 2\n      '',\n      2,\n      3,\n    ],\n  },\n});\n```\n\nFor more example cases (nested objects or arrays, long text diffs) check `packages/jsondiffpatch/test/examples/`\n\nIf you want to understand deltas, see [delta format documentation](docs/deltas.md)\n\n## Installing\n\n### NPM\n\nThis works for node, or in browsers if you already do bundling on your app\n\n```sh\nnpm install jsondiffpatch\n```\n\n```js\nimport {* as jsondiffpatch} from 'jsondiffpatch';\nconst jsondiffpatchInstance = jsondiffpatch.create(options);\n```\n\n### browser\n\nIn a browser, you can load a bundle using a tool like [esm.sh](https://esm.sh) or [Skypack](https://www.skypack.dev).\n\n## Options\n\n```ts\nimport * as jsondiffpatch from 'jsondiffpatch';\n\n// Only import if you want text diffs using diff-match-patch\nimport { diff_match_patch } from '@dmsnell/diff-match-patch';\n\nconst jsondiffpatchInstance = jsondiffpatch.create({\n  // used to match objects when diffing arrays, by default only === operator is used\n  objectHash: function (obj) {\n    // this function is used only to when objects are not equal by ref\n    return obj._id || obj.id;\n  },\n  arrays: {\n    // default true, detect items moved inside the array (otherwise they will be registered as remove+add)\n    detectMove: true,\n    // default false, the value of items moved is not included in deltas\n    includeValueOnMove: false,\n  },\n  textDiff: {\n    // If using text diffs, it's required to pass in the diff-match-patch library in through this proprty.\n    // Alternatively, you can import jsondiffpatch using `jsondiffpatch/with-text-diffs` to avoid having to pass in diff-match-patch through the options.\n    diffMatchPatch: diff_match_patch,\n    // default 60, minimum string length (left and right sides) to use text diff algorithm: google-diff-match-patch\n    minLength: 60,\n  },\n  propertyFilter: function (name, context) {\n    /*\n       this optional function can be specified to ignore object properties (eg. volatile data)\n        name: property name, present in either context.left or context.right objects\n        context: the diff context (has context.left and context.right objects)\n      */\n    return name.slice(0, 1) !== '$';\n  },\n  cloneDiffValues: false /* default false. if true, values in the obtained delta will be cloned\n      (using jsondiffpatch.clone by default), to ensure delta keeps no references to left or right objects. this becomes useful if you're diffing and patching the same objects multiple times without serializing deltas.\n      instead of true, a function can be specified here to provide a custom clone(value).\n      */\n  omitRemovedValues: false /* if you don't need to unpatch (reverse deltas),\n      \"old\"/\"left\" values (removed or replaced) are not included in the delta.\n      you can set this to true to get more compact deltas.\n      */,\n});\n```\n\n## Visual Diff\n\n```html\n<!doctype html>\n<html>\n  <head>\n    <link rel=\"stylesheet\" href=\"./style.css\" type=\"text/css\" />\n    <link\n      rel=\"stylesheet\"\n      href=\"https://esm.sh/jsondiffpatch@0.6.0/lib/formatters/styles/html.css\"\n      type=\"text/css\"\n    />\n    <link\n      rel=\"stylesheet\"\n      href=\"https://esm.sh/jsondiffpatch@0.6.0/lib/formatters/styles/annotated.css\"\n      type=\"text/css\"\n    />\n  </head>\n  <body>\n    <div id=\"visual\"></div>\n    <hr />\n    <div id=\"annotated\"></div>\n    <script type=\"module\">\n      import * as jsondiffpatch from 'https://esm.sh/jsondiffpatch@0.6.0';\n      import * as annotatedFormatter from 'https://esm.sh/jsondiffpatch@0.6.0/formatters/annotated';\n      import * as htmlFormatter from 'https://esm.sh/jsondiffpatch@0.6.0/formatters/html';\n\n      const left = { a: 3, b: 4 };\n      const right = { a: 5, c: 9 };\n      const delta = jsondiffpatch.diff(left, right);\n\n      // beautiful html diff\n      document.getElementById('visual').innerHTML = htmlFormatter.format(\n        delta,\n        left,\n      );\n\n      // self-explained json\n      document.getElementById('annotated').innerHTML =\n        annotatedFormatter.format(delta, left);\n    </script>\n  </body>\n</html>\n```\n\nTo see formatters in action check the [Live Demo](https://jsondiffpatch.com).\n\nFor more details check [Formatters documentation](docs/formatters.md)\n\n## Plugins\n\n`diff()`, `patch()` and `reverse()` functions are implemented using Pipes & Filters pattern, making it extremely customizable by adding or replacing filters on a pipe.\n\nCheck [Plugins documentation](docs/plugins.md) for details.\n\n## Related Projects\n\n- [jsondiffpatch.net (C#)\n  ](https://github.com/wbish/jsondiffpatch.net)\n- [SystemTextJson.JsonDiffPatch\n  (C#)](https://github.com/weichch/system-text-json-jsondiffpatch)\n- [Go JSON Diff (and Patch)\n  ](https://github.com/yudai/gojsondiff)\n- [json-diff-patch (python)](https://github.com/apack1001/json-diff-patch)\n- [jsondiffpatch-react](https://github.com/bluepeter/jsondiffpatch-react), also check docs for [usage in react](/docs/react.md)\n\n## All contributors ✨\n\n<a href=\"https://github.com/benjamine/jsondiffpatch/graphs/contributors\">\n  <p align=\"center\">\n    <img width=\"720\" src=\"https://contrib.rocks/image?repo=benjamine/jsondiffpatch\" alt=\"A table of avatars from the project's contributors\" />\n  </p>\n</a>\n","publish_time":1778799387144,"_cnpm_publish_time":1778799387144,"dist-tags":{"latest":"0.7.7"}}