{"id":13555751,"url":"https://github.com/bruth/jsonpatch-js","last_synced_at":"2025-04-05T10:08:05.657Z","repository":{"id":1744998,"uuid":"2570872","full_name":"bruth/jsonpatch-js","owner":"bruth","description":"A JavaScript implementation of the JSON Media Type for partial modifications: http://tools.ietf.org/html/rfc6902","archived":false,"fork":false,"pushed_at":"2017-08-21T17:51:11.000Z","size":285,"stargazers_count":181,"open_issues_count":6,"forks_count":22,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-03-29T09:10:13.875Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://bruth.github.io/jsonpatch-js","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bruth.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}},"created_at":"2011-10-13T17:02:48.000Z","updated_at":"2024-02-01T02:58:03.000Z","dependencies_parsed_at":"2022-08-28T13:10:30.404Z","dependency_job_id":null,"html_url":"https://github.com/bruth/jsonpatch-js","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bruth%2Fjsonpatch-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bruth%2Fjsonpatch-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bruth%2Fjsonpatch-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bruth%2Fjsonpatch-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bruth","download_url":"https://codeload.github.com/bruth/jsonpatch-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247318744,"owners_count":20919484,"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-01T12:03:23.714Z","updated_at":"2025-04-05T10:08:05.638Z","avatar_url":"https://github.com/bruth.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","others"],"sub_categories":[],"readme":"# jsonpatch-js\n\n[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/bruth/jsonpatch-js/trend.png)](https://bitdeli.com/free \"Bitdeli Badge\")\n\nLibrary to apply JSON Patches in JavaScript\n\n- JSON Patch - http://tools.ietf.org/html/rfc6902\n- JSON Pointer - http://tools.ietf.org/html/rfc6901\n\njsonpatch-js works as in the browser as a script, as a Node module and as an\nAMD module.\n\n## Install\n\n**Bower**\n\n```\nbower install json-patch\n```\n\n**NPM**\n\n```\nnpm install json-patch\n```\n\n**Note: at this time, all operations are applied in-place.**\n\n## Methods\n\n**`jsonpatch.apply(document, patch)`**\n\nApplies a patch to the document\n\n**`jsonpatch.compile(patch)`**\n\nCompiles a patch and returns a function that takes a document to apply the patch to.\n\n## Patch Operations\n\n### Add\n\nPatch syntax: `{op: 'add', path: \u003cpath\u003e, value: \u003cvalue\u003e}`\n\n```javascript\n// Add property, result: {foo: 'bar'}\njsonpatch.apply({}, [{op: 'add', path: '/foo', value: 'bar'}]);\n\n// Add array element, result: {foo: [1, 2, 3]}\njsonpatch.apply({foo: [1, 3]}, [{op: 'add', path: '/foo/1', value: 2}]);\n\n// Complex, result: {foo: [{bar: 'baz'}]}\njsonpatch.apply({foo: [{}]}, [{op: 'add', path: '/foo/0/bar', value: 'baz'}]);\n```\n\n### Remove\n\nPatch syntax: `{op: 'remove', path: \u003cpath\u003e}`\n\n```javascript\n// Remove property, result: {}\njsonpatch.apply({foo: 'bar'}, [{op: 'remove', path: '/foo'}]);\n\n// Remove array element, result: {foo: [1, 3]}\njsonpatch.apply({foo: [1, 2, 3]}, [{op: 'remove', path: '/foo/1'}]);\n\n// Complex, result: {foo: [{}]}\njsonpatch.apply({foo: [{bar: 'baz'}]}, [{op: 'remove', path: '/foo/0/bar'}]);\n```\n\n### Replace\n\nPatch syntax: `{op: 'replace', path: \u003cpath\u003e, value: \u003cvalue\u003e}`\n\n```javascript\n// Replace property, result: {foo: 1}\njsonpatch.apply({foo: 'bar'}, [{op: 'replace', path: '/foo', value: 1}]);\n\n// Replace array element, result: {foo: [1, 4, 3]}\njsonpatch.apply({foo: [1, 2, 3]}, [{op: 'replace', path: '/foo/1', value: 4}]);\n\n// Complex, result: {foo: [{bar: 1}]}\njsonpatch.apply({foo: [{bar: 'baz'}]}, [{op: 'replace', path: '/foo/0/bar', value: 1}]);\n```\n\n### Move\n\nPatch syntax: `{op: 'move', from: \u003cpath\u003e, path: \u003cpath\u003e}`\n\n```javascript\n// Move property, result {bar: [1, 2, 3]}\njsonpatch.apply({foo: [1, 2, 3]}, [{op: 'move', from: '/foo', path: '/bar'}]);\n```\n\n### Copy\n\nPatch syntax: `{op: 'copy', from: \u003cpath\u003e, path: \u003cpath\u003e}`\n\n```javascript\n// Copy property, result {foo: [1, 2, 3], bar: 2}\njsonpatch.apply({foo: [1, 2, 3]}, [{op: 'copy', from: '/foo/1', path: '/bar'}]);\n```\n\n### Test\n\nPatch syntax: `{op: 'test', path: \u003cpath\u003e, value: \u003cvalue\u003e}`\n\n```javascript\n// Test equality of property to value, result: true\njsonpatch.apply({foo: 'bar'}, [{op: 'test', path: '/foo', value: 'bar'}]\n```\n\n*Changed in 0.5.0*\n\nThe return value is no longer a boolean, but now the the document itself which adheres correctly to the specification. It the test fails, a `PatchTestFailed` error will be thrown.\n\n## Error Types\n\n**`JSONPatchError`**\n\nBase error type which all patch errors extend from.\n\n**`InvalidPointerError`**\n\nThrown when the pointer is invalid.\n\n**`InvalidPatchError`**\n\nThrown when the patch itself has an invalid syntax.\n\n**`PatchConflictError`**\n\nThrown when there is a conflic with applying the patch to the document.\n\n**`PatchTestFailed`**\n\nThrown when a test operation is applied and fails.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbruth%2Fjsonpatch-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbruth%2Fjsonpatch-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbruth%2Fjsonpatch-js/lists"}