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. This has the following tradeoffs:
DROP
and KEEP
, belownpm install @broofa/jsondiff
const jsondiff = require('@broofa/jsondiff');
const before = {a: 'Hello', b: 'you', c: ['dark', 'crazy'], d: 'bastard'};
const after = {a: 'Hello', c: ['dark', 'mysterious'], d: 'world'};
// Create a patch
const patch = jsondiff.diff(before, after); // ⇨ { b: '-', c: [ '+', 'mysterious' ], d: 'world' }
// Apply it to the original
const patched = jsondiff.patch(before, patch); // ⇨ { a: 'Hello', c: [ 'dark', 'mysterious' ], d: 'world' }
// 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 patchObject
to before
and returns the result.
Note: Any result value that is deep-equal to it's before
counterpart will
reference simply reference the 'before' value. Thus, ===
can be used to test
for deep equality.
Similar to patch(), but omits values not defined in patchObject
. I.e. Creates
a version of before
as "masked" by the patchObject.
Shorthand for patch(before, diff(before, after))
. Useful for
updating an 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 minor caveats:
jsondiff.DROP
("-
") string is used to indicate deleted
valuesjsondiff.KEEP
("+
") stringNote: The use of DROP
and KEEP
is, 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.