Registry / testing / json-schema-compare

json-schema-compare

JSON →
library0.2.2jsnpmunverified

Compare JSON schemas intelligently, ignoring order and normalization differences. Version 0.2.2 is the latest stable release. The library handles sorting of arrays (like required, enum, type, dependencies), treats undefined/true/{} as equivalent, and allows ignoring specific keywords via options. It is designed for JSON schema comparison in Node.js, with CommonJS support only.

npm install json-schema-compare
INSTALL
IMPORT
SIG · JSON-SCHEMA-COMPAR
J
json-schema-compare
testingjavascriptv0.2.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (compare function)
const compare = require('json-schema-compare')
import compare from 'json-schema-compare'
Package is CJS-only; no ES module export.

Demonstrates comparing two JSON schemas with different key ordering, returning true because the package normalizes arrays.

const compare = require('json-schema-compare'); const schema1 = { type: 'object', required: ['name', 'age'], properties: { name: { type: 'string' }, age: { type: 'number', minimum: 0 } } }; const schema2 = { type: 'object', required: ['age', 'name'], properties: { name: { type: 'string' }, age: { type: 'number', minimum: 0 } } }; const isEqual = compare(schema1, schema2); console.log(isEqual); // true
Debug
Known issues
gotchaThe comparison treats undefined, true, and {} as equivalent for any schema or sub-schema. Be aware when expecting strict equality.
fix
If you need strict equality, don't use this library; rely on deep equality libraries.
affects: >=0.0.0
gotchaFor minLength, minItems, and minProperties, undefined and 0 are considered equal. This might cause unexpected results if you rely on the presence of a minimum constraint.
fix
If distinction is needed, set the value to -1 or use a custom comparator.
affects: >=0.0.0
gotchaFor uniqueItems, undefined and false are treated as equal. This aligns with JSON Schema spec, but may surprise users expecting strict boolean comparison.
fix
Set uniqueItems explicitly to true or false if you need to distinguish.
affects: >=0.0.0
deprecatedThe package has not been updated since 2019. No known breaking changes, but it may lack support for newer JSON Schema drafts (2020-12, 2019-09).
fix
Consider using @hyperjump/json-schema or ajv for newer draft support; for simple comparison, keep using this library.
affects: 0.2.2
Errors
Common errors & fixes
Cannot find module 'json-schema-compare'
Package not installed or wrong require path.
fix
Run npm install json-schema-compare --save and ensure the require is 'json-schema-compare' (not mispelled).
compare is not a function
Incorrect import method (using ES module import or destructuring incorrectly).
fix
Use const compare = require('json-schema-compare'); (CommonJS).
Options must be an object
Third argument provided is not an object.
fix
Pass options as an object, e.g., compare(schema1, schema2, { ignore: ['title'] }).
Upgrade
Version history
0.2.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
json-schema-compare — npm install json-schema-compare · libregistry