{"id":20937381,"url":"https://github.com/caohanyang/json_diff_rfc6902","last_synced_at":"2025-12-12T04:22:20.991Z","repository":{"id":57142861,"uuid":"50999283","full_name":"caohanyang/json_diff_rfc6902","owner":"caohanyang","description":"This is the framework to handle JSON diff and patch based on RFC6902","archived":false,"fork":false,"pushed_at":"2018-01-31T22:16:01.000Z","size":681,"stargazers_count":21,"open_issues_count":5,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-07-09T04:09:30.070Z","etag":null,"topics":["diff","json","json-diff","json-patch","patch","rfc-6902"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/caohanyang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-03T12:49:05.000Z","updated_at":"2025-01-28T18:15:19.000Z","dependencies_parsed_at":"2022-08-31T21:00:25.784Z","dependency_job_id":null,"html_url":"https://github.com/caohanyang/json_diff_rfc6902","commit_stats":null,"previous_names":["caohanyang/json-diff"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/caohanyang/json_diff_rfc6902","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caohanyang%2Fjson_diff_rfc6902","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caohanyang%2Fjson_diff_rfc6902/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caohanyang%2Fjson_diff_rfc6902/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caohanyang%2Fjson_diff_rfc6902/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/caohanyang","download_url":"https://codeload.github.com/caohanyang/json_diff_rfc6902/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caohanyang%2Fjson_diff_rfc6902/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265311742,"owners_count":23745122,"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","json","json-diff","json-patch","patch","rfc-6902"],"created_at":"2024-11-18T22:35:37.449Z","updated_at":"2025-12-12T04:22:20.951Z","avatar_url":"https://github.com/caohanyang.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSON-Diff\nJSON-Diff is to diff two JSON object and generate the patch, which is compliant to [JSON Patch RFC6902](https://tools.ietf.org/html/rfc6902).\n\nYou can use JSON-Diff to\n- **diff** two JSON object\n- **apply** patches to get JSON\n\nJSON-Diff is able to handle operations:\n\n_**Object**_\n- **add**\n- **remove**\n- **replace**\n- **copy**\n- **move**\n\n_**Array**_\n- **add**\n- **remove**\n- **replace**\n- **copy**\n- **move**\n- **permutation**\n\n## INSTALL\n\n### npm\n`npm install json-diff-rfc6902 --save`\n\n### bower\n`bower install json-diff-rfc6902 --save`\n\n- ```json-diff-rfc6902.js``` main bundle\n- ```jdr```  global variable\n\n## API\n\n```js\nvar jdr = require('json-diff-rfc6902');\n\n// diff the two JSON objects to get the pathes\nvar jdr_patch = jdr.diff(f_old, f_new [, options]);\n\n// The third parameter is optional, use the object options.\n// Default:\noptions.OBJ_COM = true   // Generate copy and move for object\noptions.ARR_COM = true   // Generate minimal patch for array\noptions.HASH_ID = null   // manually set the hash value\n\n// For example, if options.HASH_ID = \"title\", it will get the property value \"title\" of the elements in the array, and use them as the hash value to execute the operations transformation algorithem.\nvar jdr_patch = jdr.diff(f_old, f_new, {OBJ_COM: true, ARR_COM: true, HASH_ID: \"title\"});\n\n// apply the patches to the f_old object\njdr.apply(f_old, jdr_patch);\n\n```\n\n## TEST\n`npm install -g mocha`\n\n`npm install -g fast-json-patch jiff json8-patch rfc6902`\n\n`cd tests`\n\n`node diff.js`\n\n`mocha`\n\n# Test 1\n\nOBJ_PROP_INS\n\nThis is an object where a property is added.\n\n# Test 2\n\nOBJ_PROP_DEL\n\nThis is an object where a property is removed.\n\n# Test 3\n\nOBJ_PROP_MOD\n\nThis is an object where a property value is modified.\n\n# Test 4\n\nOBJ_PROP_CPY\n\nThis is an object where a property is copied.\n\n# Test 5\n\nOBJ_PROP_REN\n\nThis is an object where a field is renamed.\n\n# Test 6\n\nARR_OBJ_UNSHIFT\n\nThis is an array of objects with a insertion at the beginning of the array.\n\n# Test 7\n\nARR_OBJ_PUSH\n\nThis is an array of objects with a insertion at the end of the array.\n\n# Test 8\n\nARR_OBJ_RINS\n\nThis is an array of objects with a insertion in the middle of the array.\n\n# Test 9\n\nARR_OBJ_SHIFT\n\nThis is an array of objects with a deletion of the first element.\n\n# Test 10\n\nARR_OBJ_POP\n\nThis is an array of objects with a deletion of the last element\n\n# Test 11\n\nARR_OBJ_RDEL\n\nThis is an array of objects with a deletion of the moddle element\n\n# Test 12\n\nARR_OBJ_BREPLACE\n\nThis is an array of objects with a replacement of the first element\n\n# Test 13\n\nARR_OBJ_EREPLACE\n\nThis is an array of objects with a replacement of the last element\n\n# Test 14\n\nARR_OBJ_MREPLACE\n\nThis is an array of objects with a replacement of the middle element\n\n# Test 15\n\nARR_OBJ_CPY\n\nThis is an array of objects where a object is copied.\n\n# Test 16\n\nARR_OBJ_PERM1\n\nPermutation of a objects in an array of objects. [a, b, c] =\u003e [a, c, b]\n\n# Test 17\n\nARR_OBJ_PERM2\n\nPermutation of a objects in an array of objects. [a, b, c] =\u003e [b, c, a]\n\n# Test 18\n\nARR_OBJ_PERM3\n\nPermutation of a objects in an array of objects. [a, b, c] =\u003e [b, a, c]\n\n# Test 19\n\nARR_OBJ_PERM4\n\nPermutation of a objects in an array of objects. [a, b, c] =\u003e [c, b, a]\n\n# Test 20\n\nARR_OBJ_PERM5\n\nPermutation of a objects in an array of objects. [a, b, c] =\u003e [c, a, b]\n\n# Test 21\n\nARR_OBJ_MOD\n\nThis is an array of objects where every object is added a field.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaohanyang%2Fjson_diff_rfc6902","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaohanyang%2Fjson_diff_rfc6902","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaohanyang%2Fjson_diff_rfc6902/lists"}