
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
json-assert
Advanced tools
This program checks that a javascript object matches another. The main use case is for use in testing a JSON API.
The difference between this and _.isEqual is that json-assert accepts a function which will run that can perform addition checks. See the examples below.
The difference between this and JSON schema is that json-assert is less verbose, but it is also less flexible.
npm install json-assert --save
npm test
var ja = require('json-assert');
// basic things must match
ja.isEqual({ a: 3}, { b: 4}); // false
ja.isEqual({ a: 3}, { a: 3}); // true
// we don't care what the value is as long as it exists.
ja.isEqual({ a: ja.dontCare }, { a: 3}); // true
// it must exist and match the type (typeof)
ja.isEqual({ a: ja.matchType('string') }, { a: 4}); // false
ja.isEqual({ a: ja.matchType('string') }, { a: "4"}); // true
// we don't care if it exists or not
ja.isEqual({ a: ja.optional }, { a: 4 }); // true
ja.isEqual({ a: ja.optional }, { }); // true
Here is a more realistic example.
var ja = require('json-assert');
var request = require('request');
function testAjax(url, expected) {
request(url, function (error, response, body) {
assert(!error);
assert.equal(response.statusCode, 200);
assert(ja.isEqual(expected, JSON.parse(body)));
});
}
testAjax('http://api.test.com', {
name: "bob",
age: 45,
lastLogin: ja.matchType('string')
});
Make sure your code:
Then submit a pull request.
FAQs
check json object matches template
We found that json-assert 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.