Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@broofa/jsondiff
Advanced tools
Pragmatic, intuitive diffing and patching of JSON objects
There are variety of modules available that can diff and patch JSON data structures. Here's a quick run down:
Module | Size | Patch format | Notes |
---|---|---|---|
@broofa/jsondiff | 0.7K | Overlay | Readable patches |
deep-diff | 3.5K | RFC9602-like | Most popular module |
rfc9602 | 2K | RFC9602 | See below |
fast-json-patch | 4K | RFC9602 | See below |
The main difference between these modules is in the patch object structure. Most (all?) of the other modules use a structure based on or similar to RFC9602, which is composed of a series of operations that describe how to transform the target object. In contrast, the patches in this module act as an "overlay" that is copied onto the target object. There are tradeoffs to this, some good, some bad:
DROP
and KEEP
values in "Patch
Objects", below. This may be off-putting to some readers.npm install @broofa/jsondiff
const jsondiff = require('@broofa/jsondiff');
const before = {a: 'Hello', b: 'you', c: ['big', 'bad'], d: 'beast'};
const after = {a: 'Hi', c: ['big', 'bad', 'bold'], d: 'beast'};
// Create a patch
// Note the use of DROP (-) and KEEP(+) values
const patch = jsondiff.diff(before, after); // ⇨ { a: 'Hi', b: '-', c: [ '+', '+', 'bold' ] }
// Apply it to the original
const patched = jsondiff.patch(before, patch); // ⇨ { a: 'Hi', c: [ 'big', 'bad', 'bold' ], d: 'beast' }
// Get the expected result
assert.deepEqual(after, patched); // Passes!
Creates and returns a "patch object" that describes the differences between
before
and after
. This object is suitable for use in patch()
.
Applies a patch
object to before
and returns the result.
Note: Any result value that is deep-equal to it's before
counterpart will
reference the 'before' value directly, allowing ===
to be used as a test
for deep equality.
Shorthand for jsondiff.patch(before, jsondiff.diff(before, after))
. Useful
for mutating an object only where values have actually changed.
Patch objects are JSON objects with the same structure (schema) as the object they apply to. Applying a patch is (almost) as simple as doing a deep copy of the patch onto the target object. There are two special cases:
jsondiff.DROP
("-
") values are "dropped" (deleted or set
to undefined
)jsondiff.KEEP
("+
") values are "kept" (resolve to the corresponding
value in the target)Note: DROP
and KEEP
are, admittedly, a hack. If these exact string values
appear in data outside of patch objects, diff()
and patch()
may not function
correctly. That said, this is not expected to be an issue in real-world
conditions. (Both strings include a "private use" Unicode character that should
make them fairly unique.)
Markdown generated from src/README_js.md by
FAQs
Pragmatic, intuitive diffing and patching of JSON objects
The npm package @broofa/jsondiff receives a total of 96 weekly downloads. As such, @broofa/jsondiff popularity was classified as not popular.
We found that @broofa/jsondiff 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.