{"id":19122957,"url":"https://github.com/digitalbazaar/jsonld-patch","last_synced_at":"2025-05-05T18:28:26.801Z","repository":{"id":54298817,"uuid":"127435588","full_name":"digitalbazaar/jsonld-patch","owner":"digitalbazaar","description":"JSON patch for JSON-LD","archived":false,"fork":false,"pushed_at":"2021-02-25T19:39:34.000Z","size":26,"stargazers_count":7,"open_issues_count":2,"forks_count":0,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-05-02T14:21:36.184Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/digitalbazaar.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2018-03-30T14:13:08.000Z","updated_at":"2025-03-28T04:02:08.000Z","dependencies_parsed_at":"2022-08-13T11:20:38.239Z","dependency_job_id":null,"html_url":"https://github.com/digitalbazaar/jsonld-patch","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalbazaar%2Fjsonld-patch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalbazaar%2Fjsonld-patch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalbazaar%2Fjsonld-patch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalbazaar%2Fjsonld-patch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/digitalbazaar","download_url":"https://codeload.github.com/digitalbazaar/jsonld-patch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252552510,"owners_count":21766713,"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-11-09T05:23:44.423Z","updated_at":"2025-05-05T18:28:26.756Z","avatar_url":"https://github.com/digitalbazaar.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSON-LD Patch\n\nThis library provides an API for applying JSON patches to JSON-LD documents.\n\nJSON patches may be represented in JSON-LD by using hte will be interpreted as JSON-LD using the JSON-LD Patch\n`@context`.\n\n## The API\n\n  * api.applyPatch(document, patch)\n\n## Quick Examples\n\n### Installation\n\n```\nnpm install jsonld-patch\n```\n\n### Simple patch\n\n```js\nconst jldp = require('jsonld-patch');\n\nconst document = {\n  \"@context\": \"http://schema.org/\",\n  \"@type\": \"Person\",\n  \"name\": \"Alice\"\n};\n\nconst patch = [\n  {op: 'add', path: '/email', value: 'pdoe@example.com'}\n];\n\nconst {newDocument} = jldp.applyPatch({document, patch});\n\n/*\nnewDocument is:\n{\n  \"@context\": \"http://schema.org/\",\n  \"@type\": \"Person\",\n  \"name\": \"Alice\",\n  \"email\": \"alice@example.com\"\n}\n*/\n```\n\n### Contextual patch\n\n```js\nconst document = {\n  \"@type\": \"http://schema.org/Person\",\n  \"http://schema.org/name\": \"Alice\"\n};\n\nconst patch = [\n  {op: 'add', path: '/email', value: 'alice@example.com'}\n];\n\nconst context = {\n  \"@context\": \"http://schema.org/\"\n};\n\n// document will be compacted to the new context, then patched\nconst {newDocument} = jldp.applyPatch({document, patch, context});\n\n/*\nnewDocument is:\n{\n  \"@context\": \"http://schema.org/\",\n  \"@type\": \"Person\",\n  \"name\": \"Alice\",\n  \"email\": \"alice@example.com\"\n}\n*/\n\n```\n\n### Frame and patch\n\n```js\nconst document = {\n  \"@context\": \"http://schema.org/\",\n  \"@id\": \"http://example.com/alice\",\n  \"@type\": \"Person\",\n  \"name\": \"Alice\",\n  \"knows\": {\n    \"@id\": \"http://example.com/bob\",\n    \"@type\": \"Person\",\n    \"name\": \"Bob\",\n    \"knows\": \"http://example.com/alice\"\n  }\n};\n\nconst patch = [\n  {op: 'add', path: '/email', value: 'bob@example.com'}\n];\n\nconst frame = {\n  \"@context\": \"http://schema.org/\",\n  \"@id\": \"http://example.com/bob\"\n}\n\nconst {newDocument} = jldp.applyPatch({document, patch, frame});\n\n/*\nnewDocument is:\n{\n  \"@context\": \"http://schema.org/\",\n  \"@type\": \"Person\",\n  \"@id\": \"http://example.com/bob\",\n  \"name\": \"Bob\",\n  \"email\": \"bob@example.com\",\n  \"knows\": {\n    \"@id\": \"http://example.com/alice\",\n    \"@type\": \"Person\",\n    \"name\": \"Alice\",\n    \"knows\": \"http://example.com/bob\"\n  }\n}\n*/\n\n// Note: newDocument could be reframed back to alice at its root using jsonld:\n\nconst aliceFrame = {\n  \"@context\": \"http://schema.org/\",\n  \"@id\": \"http://example.com/alice\"\n}\n\nconst aliceAtRoot = jsonld.frame(newDocument, aliceFrame);\n\n\n\n/*\nconst jsonpatch = require('fast-json-patch');\n\nconst document = {\n  \"@context\": \"http://schema.org/\",\n  \"@type\": \"Person\",\n  \"name\": \"Alice\",\n};\n\nconst observer = jsonpatch.observe(document);\n\ndocument.email = 'alice@example.com';\nconst patch = jsonpatch.generate(observer);\njsonpatch.unobserve(document, observer);\n\nconsole.log('patch', patch);\n*/\n\n```\n\n## API Documentation\n\n### Apply a JSON patch\n\n### Generate a JSON patch\n\nA JSON patch can be generated by observing changes to a document.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigitalbazaar%2Fjsonld-patch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdigitalbazaar%2Fjsonld-patch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigitalbazaar%2Fjsonld-patch/lists"}