
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
json-patch-utils
Advanced tools
Utility functions for implementing JSON Patch according to [RFC 6902]
$ npm install --save-dev json-patch-utils
Creates a JSON Patches given an operator, path and a value
import { createPatch } from 'json-patch-utils'
createPatch('add', '/foo', 123) // { op: 'add', path: '/foo', value: 123 }
createPatch('move', 'foo', 'bar') // [Error: The path "foo" did not match the encoded path regexp: /^(\/[a-z0-9~\\\-%^|"\ ]*)*$/gi,The path "bar" did not match the encoded path regexp: /^(\/[a-z0-9~\\\-%^|"\ ]*)*$/gi]
Tests if a given object is a valid JSON Patch object according to https://tools.ietf.org/html/rfc6902
import { isPatch } from 'json-patch-utils'
let validPatch = { op: 'add', path: '/foo/bar', value: 'baz' }
let invalidPatch = { op: 'foo', path: 'bar' }
if(isPatch(validPatch) === true) {
// Patch can be safely applied
}
isPatch(invalidPatch) // [
// 'The path "bar" did not match the encoded path regexp: /^(\\/[a-z0-9~\\\\\\-%^|"\\ ]*)*$/gi',
// 'The operation name is not among the valid names add, replace, test, remove, move, copy'
// ]
Tests if a given string is a valid JSON Pointer according to https://tools.ietf.org/html/rfc6901
import { isPath } from 'json-patch-utils'
isPath('/foo/bar') // true
isPath('foo') // The path "foo" did not match the encoded path regexp: /^(\/[a-z0-9~\\\-%^|"\ ]*)*$/gi
Tests if a given string is a valid JSON Patch operation name
import { isOperation } from 'json-patch-utils'
isOperation('add') // true
isOperation('foo') // The operation name is not among the valid names add, replace, test, remove, move, copy
Tests if a given value corresponds to the given operation
import { isValueForOperation } from 'json-patch-utils'
isValueForOperation('move', '/foo') // true
isValueForOperation('add', undefined) // The value or from path provided must be different than undefined
isValueForOperation('copy', 'foo') // The path "foo" did not match the encoded path regexp: /^(\/[a-z0-9~\\\-%^|"\ ]*)*$/gi
Decodes a path according to https://tools.ietf.org/html/rfc6901 by replacing special symbols
import { decodePath } from 'json-patch-utils'
decodePath('/foo/bar') // '/foo/bar'
decodePath('/foo~0bar~1') // '/foo/bar~'
Convert a path into a list of strings. Useful when traversing a path on a JSON Document
import { listPath } from 'json-patch-utils'
listPath('/foo/bar/') // ['foo', 'bar']
listPath('/foo~0bar~1') // ['foo', 'bar~']
import Baobab from 'baobab'
import { applyBaobabJsPatch, createPatch } from 'json-patch-utils'
let tree = new Baobab({
foo: {
bar: 123
}
})
let patch = createPatch('replace', '/foo/bar', 1000)
applyBaobabJsPatch(tree, patch)
tree.select('foo', 'bar').get() // 1000
https://github.com/Starcounter-Jack/JSON-Patch - for the tests battery in test/tests.json and test/spec_tests.json
Feel free to open issues to propose stuff and participate. Pull requests are also welcome.
FAQs
Utility functions for implementing JSON Patch according to [RFC 6902]
The npm package json-patch-utils receives a total of 25 weekly downloads. As such, json-patch-utils popularity was classified as not popular.
We found that json-patch-utils 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
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.