{"id":25080835,"url":"https://github.com/lukascivil/json-difference","last_synced_at":"2025-04-04T15:07:02.369Z","repository":{"id":33023131,"uuid":"149703544","full_name":"lukascivil/json-difference","owner":"lukascivil","description":"A simple way to find the difference between two objects or json diff","archived":false,"fork":false,"pushed_at":"2024-11-19T04:50:46.000Z","size":7058,"stargazers_count":57,"open_issues_count":12,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-28T14:05:50.764Z","etag":null,"topics":["diff","javascript","json","object","structured-data"],"latest_commit_sha":null,"homepage":"https://lukascivil.github.io/json-difference/","language":"TypeScript","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/lukascivil.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2018-09-21T03:16:05.000Z","updated_at":"2025-03-28T04:17:32.000Z","dependencies_parsed_at":"2023-12-30T16:30:48.453Z","dependency_job_id":"5635fbc3-308b-400e-9290-4a534105450e","html_url":"https://github.com/lukascivil/json-difference","commit_stats":null,"previous_names":["lukascivil/jsondiffer"],"tags_count":63,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukascivil%2Fjson-difference","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukascivil%2Fjson-difference/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukascivil%2Fjson-difference/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukascivil%2Fjson-difference/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lukascivil","download_url":"https://codeload.github.com/lukascivil/json-difference/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247198445,"owners_count":20900079,"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":["diff","javascript","json","object","structured-data"],"created_at":"2025-02-07T04:26:47.074Z","updated_at":"2025-04-04T15:07:02.349Z","avatar_url":"https://github.com/lukascivil.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JsonDifference\n\n[![Total Downloads](https://img.shields.io/npm/dt/json-difference.svg)](https://img.shields.io/npm/dt/json-difference.svg)\n[![npm version](http://img.shields.io/npm/v/json-difference.svg?style=flat)](https://www.npmjs.com/package/json-difference 'View this project on npm')\n[![CD](https://github.com/lukascivil/json-difference/actions/workflows/cd.yml/badge.svg)](https://github.com/lukascivil/json-difference/actions/workflows/cd.yml)\n[![Release and Publish](https://github.com/lukascivil/json-difference/actions/workflows/release-and-publish.yml/badge.svg)](https://github.com/lukascivil/json-difference/actions/workflows/release-and-publish.yml)\n[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)\n[![codecov](https://codecov.io/gh/lukascivil/json-difference/branch/master/graph/badge.svg?token=um2lc3uRKd)](https://codecov.io/gh/lukascivil/json-difference)\n[![MIT License](https://img.shields.io/npm/l/deep-object-diff.svg?style=flat)](https://github.com/lukascivil/jsondiffer/blob/master/LICENSE)\n\nComputes the difference between two objects and returns an intuitive result. No matter how big your JSON is, the diff will be returned pretty fast.\n\nThe question you should ask is: Given my old structure what was changed, removed or added to the new structure?\n\nThis repository contains two npm packages, json-difference and its cli version (json-difference-cli).\n\nIt's a very lightweight lib that costs only 🪶 1.95 kB │ gzip: 0.79 kB.\n\n## Live Demo\n\n[Master (deprecated link)](http://jsondifference.lukascivil.com.br)\n[Latest release (new)](https://lukascivil.github.io/json-difference/)\n\n## Installation\n\n```sh\nyarn add json-difference\n\n\n# If you want to play with the terminal version\nyarn add json-difference-cli\n```\n\nOr\n\n```html\n\u003cscript type=\"module\"\u003e\n  // https://json-difference.s3.amazonaws.com/\u003ca.b.c\u003e/json-difference-\u003ca.b.c\u003e.mjs\n  import { getDiff } from 'https://json-difference.s3.amazonaws.com/1.16.0/json-difference-1.16.0.mjs'\n\u003c/script\u003e\n```\n\n## Example\n\nRunning example:\n\n`yarn example {simple, stress}`\n\n\n\n## Usage of Json Difference\n\nMethod:\n\n`getDiff(oldStruct, newStruct)`\n\nReturns the structural difference between `oldStruct` and `newStruct`.\n\nSimple usage:\n\n```ts\nimport { getDiff } from 'json-difference'\n\nconst coffee = { color: { color1: 'black', color2: 'brown' }, special: true }\nconst oil = { color: { color1: 'red', color2: 'blue' }, special2: false, especial3: [{}] }\n\n// Get JsonDiff delta\nconst diff = getDiff(coffee, oil)\nconst diff2 = getDiff(coffee, oil, { isLodashLike: true })\n\nconsole.log(diff)\nconsole.log(diff2)\n```\n\nOutput:\n\n```json\n{\n  \"added\": [\n    [\"special2\", false],\n    [\"especial3\", []],\n    [\"especial3/0[]\", {}]\n  ],\n  \"removed\": [[\"special\", true]],\n  \"edited\": [\n    [\"color/color1\", \"black\", \"red\"],\n    [\"color/color2\", \"brown\", \"blue\"]\n  ]\n}\n```\n\n```json\n{\n  \"added\": [\n    [\"special2\", false],\n    [\"especial3\", []],\n    [\"especial3[0]\", {}]\n  ],\n  \"removed\": [[\"special\", true]],\n  \"edited\": [\n    [\"color.color1\", \"black\", \"red\"],\n    [\"color.color2\", \"brown\", \"blue\"]\n  ]\n}\n```\n\n## Usage of Json Difference CLI\n```sh\n# jd -\u003e Json Difference command\n# -o -\u003e Original or old struct\n# -m -\u003e Modified or new struct\njd -o \"{}\" -m \"[]\"\n```\n\n### Delta\nThe delta is an object that contains three properties that follow a pattern. This pattern will be shown below:\n\n| Operation     |  Pattern                                 |\n| ------------- |:----------------------------------------:|\n| \"edited\"      | [path_to_the_key, old_value, new_value]  |\n| \"added\"       | [path_to_the_key, value]                 |\n| \"removed\"     | [path_to_the_key, old_value]             |\n\n| value        |  Explanation                                               |\n| ------------ |:----------------------------------------------------------:|\n| \"__root__\"   | Indicates the root of the object                           |\n| \"@{}\"        | Indicates that the key is a non-leaf node of type Object   |\n| \"@[]\"        | Indicates that the key is a non-leaf node of type Array    |\n\n\n### Some operations\n\n| JSON original |  JSON modified  | Delta                                |\n| ------------- |:---------------:| ------------------------------------:|\n| {}            | []              | \"edited\": [ [ \"__root__\", {}, [] ] ] |\n| []            | {}              | \"edited\": [ [ \"__root__\", [], {} ] ] |\n| [{}]          | [[]]            | \"edited\": [ [ \"0[]\", {}, [] ] ]      |\n| {\"a\": \"b\"}    | {\"a\": \"c\"}      | \"edited\": [ [ \"a\", \"b\", \"c\" ] ]      |\n| {\"\":\"\"}       | {\"\": \"a\"}       | \"edited\": [ [ \"\", \"\", \"a\" ] ]        |\n| {\"\":{\"\":\"\"}}  | {\"\": {\"\": \"a\"}} | \"edited\": [ [ \"/\", \"\", \"a\" ] ]       |\n| []            | [{}]            | \"added\": [ [ \"0[]\", {} ] ]           |\n| {}            | {\"a\":\"b\"}       | \"added\": [ [ \"a\", \"b\" ] ]            |\n| {\"a\":\"b\"}     | {}              | \"removed\": [ [ \"a\", \"b\" ] ]          |\n| [{}]          | []              | \"removed\": [ [ \"0[]\", {} ] ]         |\n| [{\"\":\"\"}]     | {\"\":\"\"}         | \"added\": [ [ \"\", \"\" ] ], \"removed\": [ [ \"0[]\", {} ], [ \"0[]/\", \"\" ] ], \"edited\": [ [ \"__root__\", [], {} ] ]      |\n\nIt is important to understand that the output generated by the latest versions of Json Difference: [v1.9.1](https://github.com/lukascivil/json-difference/releases/tag/1.9.1) and [V1.15.7](https://github.com/lukascivil/json-difference/releases/tag/json-difference-1.15.7) is different. Version V1.15.7 introduces greater accuracy for the return.\n\nAnyway, to request a new feature or report a problem, just open an issue and it will be investigated.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukascivil%2Fjson-difference","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flukascivil%2Fjson-difference","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukascivil%2Fjson-difference/lists"}