Registry / storage / jsonschema-draft4

jsonschema-draft4

JSON →
library1.0.0jsnpmunverified

jsonschema-draft4 v1.0.0 provides a verbatim copy of the JSON Schema Draft 4 meta-schema as published at json-schema.org/draft-04/schema. This package is a single-file module that exports the schema object for use in validation or reference. It is not regularly updated as it represents a frozen specification. Differentiators: it is the canonical Draft 4 schema, not a validator or generator. It has no dependencies and is compatible with both CommonJS and ES modules.

npm install jsonschema-draft4
INSTALL
IMPORT
SIG · JSONSCHEMA-DRAFT4
J
jsonschema-draft4
storagejavascriptv1.0.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.

default
import schema from 'jsonschema-draft4'
const schema = require('jsonschema-draft4')
Package exports default export as schema object; CJS require also works.
default
const schema = require('jsonschema-draft4')
CommonJS require is supported.
draft4
import { draft4 } from 'jsonschema-draft4'
import draft4 from 'jsonschema-draft4'
Named export available; using default or named is equivalent.

Imports the Draft 4 meta-schema object and uses it with a validator (example with Ajv).

// Import the Draft 4 meta-schema import schema from 'jsonschema-draft4'; // Validate a schema against Draft 4 (pseudo-code, requires a validator library) // import Ajv from 'ajv'; // const ajv = new Ajv(); // const validate = ajv.compile(schema); // const mySchema = { type: 'object', properties: { name: { type: 'string' } } }; // const valid = validate(mySchema); // console.log('Schema valid:', valid); console.log(schema.title); // 'JSON Schema for JSON Schema, draft 4' console.log(schema.$schema); // 'http://json-schema.org/draft-04/schema#'
Debug
Known issues
deprecatedJSON Schema Draft 4 is superseded by Draft 6, Draft 7, and later. This package is a snapshot of the draft and is no longer maintained.
fix
Use a more recent JSON Schema version (e.g., draft-07 or 2020-12) via packages like @apidevtools/json-schema-ref-parser or ajv-formats.
affects: >=1.0.0
gotchaThe exported schema object includes a $schema property pointing to itself (http://json-schema.org/draft-04/schema#). Some validators may reject using a meta-schema that references itself without proper handling.
fix
When using Ajv, enable strict mode: new Ajv({ strict: false }). Or use the schema as a reference without self-validation.
affects: >=1.0.0
gotchaThe package does not include TypeScript type definitions. Using with TypeScript may require declaring the module.
fix
Add a declaration file: declare module 'jsonschema-draft4' { const schema: object; export default schema; }
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'jsonschema-draft4'
Package not installed or not in node_modules.
fix
npm install jsonschema-draft4
TypeError: schema is not a function
Using the imported schema as a callback instead of as an object.
fix
Use the schema object for validation reference, not as a function.
Error: Invalid JSON Schema: unknown keyword "$schema"
Validator does not recognize the meta-schema $schema property when used as a schema.
fix
Set the validator's meta option to false or use a schema ID that allows $schema.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
22 hits · last 30 days
node
22
Resources
jsonschema-draft4 — npm install jsonschema-draft4 · libregistry