Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
json-patch
Advanced tools
A JavaScript implementation of the JSON Object Notation (JSON) Patch http://tools.ietf.org/html/rfc6902 and JSON Pointer http://tools.ietf.org/html/rfc6901 specifications.
Library to apply JSON Patches in JavaScript
jsonpatch-js works as in the browser as a script, as a Node module and as an AMD module.
Bower
bower install json-patch
NPM
npm install json-patch
Note: at this time, all operations are applied in-place.
jsonpatch.apply(document, patch)
Applies a patch to the document
jsonpatch.compile(patch)
Compiles a patch and returns a function that takes a document to apply the patch to.
Patch syntax: {op: 'add', path: <path>, value: <value>}
// Add property, result: {foo: 'bar'}
jsonpatch.apply({}, [{op: 'add', path: '/foo', value: 'bar'}]);
// Add array element, result: {foo: [1, 2, 3]}
jsonpatch.apply({foo: [1, 3]}, [{op: 'add', path: '/foo/1', value: 2}]);
// Complex, result: {foo: [{bar: 'baz'}]}
jsonpatch.apply({foo: [{}]}, [{op: 'add', path: '/foo/0/bar', value: 'baz'}]);
Patch syntax: {op: 'remove', path: <path>}
// Remove property, result: {}
jsonpatch.apply({foo: 'bar'}, [{op: 'remove', path: '/foo'}]);
// Remove array element, result: {foo: [1, 3]}
jsonpatch.apply({foo: [1, 2, 3]}, [{op: 'remove', path: '/foo/1'}]);
// Complex, result: {foo: [{}]}
jsonpatch.apply({foo: [{bar: 'baz'}]}, [{op: 'remove', path: '/foo/0/bar'}]);
Patch syntax: {op: 'replace', path: <path>, value: <value>}
// Replace property, result: {foo: 1}
jsonpatch.apply({foo: 'bar'}, [{op: 'replace', path: '/foo', value: 1}]);
// Replace array element, result: {foo: [1, 4, 3]}
jsonpatch.apply({foo: [1, 2, 3]}, [{op: 'replace', path: '/foo/1', value: 4}]);
// Complex, result: {foo: [{bar: 1}]}
jsonpatch.apply({foo: [{bar: 'baz'}]}, [{op: 'replace', path: '/foo/0/bar', value: 1}]);
Patch syntax: {op: 'move', from: <path>, path: <path>}
// Move property, result {bar: [1, 2, 3]}
jsonpatch.apply({foo: [1, 2, 3]}, [{op: 'move', from: '/foo', path: '/bar'}]);
Patch syntax: {op: 'copy', from: <path>, path: <path>}
// Copy property, result {foo: [1, 2, 3], bar: 2}
jsonpatch.apply({foo: [1, 2, 3]}, [{op: 'copy', from: '/foo/1', path: '/bar'}]);
Patch syntax: {op: 'test', path: <path>, value: <value>}
// Test equality of property to value, result: true
jsonpatch.apply({foo: 'bar'}, [{op: 'test', path: '/foo', value: 'bar'}]
Changed in 0.5.0
The 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.
JSONPatchError
Base error type which all patch errors extend from.
InvalidPointerError
Thrown when the pointer is invalid.
InvalidPatchError
Thrown when the patch itself has an invalid syntax.
PatchConflictError
Thrown when there is a conflic with applying the patch to the document.
PatchTestFailed
Thrown when a test operation is applied and fails.
FAQs
A JavaScript implementation of the JSON Object Notation (JSON) Patch http://tools.ietf.org/html/rfc6902 and JSON Pointer http://tools.ietf.org/html/rfc6901 specifications.
The npm package json-patch receives a total of 11,252 weekly downloads. As such, json-patch popularity was classified as popular.
We found that json-patch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.