Registry / testing / json-schema

json-schema

JSON →
library0.4.0jsnpmunverified

Historical library implementing early JSON Schema draft specifications (draft-01 to draft-04). Current version 0.4.0 is considered finished and stable, with no active development. It provides a simple, efficient validator for the original core elements but does not support later drafts (draft-06, draft-07, 2019-09, 2020-12). Used by many legacy npm packages due to its stability and small size. Not suitable for new projects requiring current JSON Schema compliance. Alternatives: ajv (full drafts), @cfworker/json-schema (modern).

npm install json-schema
INSTALL
IMPORT
SIG · JSON-SCHEMA
J
json-schema
testingjavascriptv0.4.0
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.

validate
import { validate } from 'json-schema'
const validate = require('json-schema').validate
ESM and CJS both work; CJS via require is more common in older codebases.
Validator
import { Validator } from 'json-schema'
const Validator = require('json-schema').Validator
Validator class for custom validation options.
checkPropertyChange
import { checkPropertyChange } from 'json-schema'
Utility to check a single property change against schema.

Shows JSON Schema validation of an object instance against a schema, checking for errors using the validate function.

import { validate } from 'json-schema'; const schema = { type: 'object', properties: { name: { type: 'string' }, age: { type: 'number', minimum: 0 } }, required: ['name'] }; const instance = { name: 'Alice', age: 30 }; const result = validate(instance, schema); if (result.valid) { console.log('Valid!'); } else { console.log('Errors:', result.errors); }
Debug
Known issues
gotchaDoes not support JSON Schema drafts beyond draft-04. Using keywords like 'if/then/else', 'const', or 'contains' will be ignored or cause errors.
fix
Use ajv or @cfworker/json-schema for modern drafts.
affects: >=0.4.0
deprecatedPackage is in maintenance mode; no new features or draft updates will be added.
fix
Migrate to a maintained library (e.g., ajv).
affects: >=0.4.0
gotchaThe validate() function mutates the schema object if it has a 'definitions' property (adds a __validated flag).
fix
Clone schema before passing if needed: validate(instance, JSON.parse(JSON.stringify(schema))).
affects: >=0.2.0
gotchaErrors object uses custom properties (property, message, schema) not standard JSON Schema error format.
fix
Access result.errors[0].property, .message, .schema; not .instancePath, .keyword.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: Cannot read property 'type' of undefined
Schema is null or undefined, or schema lacks expected properties.
fix
Ensure schema is a valid object with type property: const schema = { type: 'object' };
Error: Unknown schema format: 'http://json-schema.org/draft-04/schema#'
Using a $schema keyword for draft-04? This library does not parse $schema and may choke on unknown formats.
fix
Remove $schema from schema or ensure schema is plain object without unrecognized keys.
Upgrade
Version history
0.4.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
20 hits · last 30 days
node
20
Resources