Registry / devops / json-schema-validator

json-schema-validator

JSON →
library1.1.0jsnpmunverified

A JSON schema validator wrapping tv4 and tv4-formats that loads schemas over HTTP. Version 1.1.0 is stable; release cadence is low. Differentiators include automatic fetching of referenced schemas and a CLI tool. It is a thin wrapper around tv4 for convenience.

npm install json-schema-validator
INSTALL
IMPORT
SIG · JSON-SCHEMA-VALIDA
J
json-schema-validator
devopsjavascriptv1.1.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
const Validator = require('json-schema-validator')
This package uses CommonJS (no ESM) and exports a single constructor/namespace.
Validator
const { Validator } = require('json-schema-validator')
import { Validator } from 'json-schema-validator'
No named export for Validator; only default export. Named import will fail at runtime.
simple
Validator.simple(...)
simple is a static method on the default export.

Creates a validator using the simple shortcut to load a schema over HTTP and validate a JSON object.

const Validator = require('json-schema-validator'); Validator.simple('http://json-schema.org/geo', function (error, v) { if (error) { console.error(error.message); return; } const result = v.validate( { latitude: 53.0, longitude: 43.0 }, 'http://json-schema.org/geo' ); console.log(result.valid ? 'Valid' : 'Invalid'); });
Debug
Known issues
breakingSchema loading fails if network is unavailable or if the URI is unreachable. This can cause fetchSchemas to error silently.
fix
Ensure all schema URIs are accessible or use a local file-based schema loader.
affects: >=1.0.0
gotchaThe package does not support ESM imports; using import will result in an error.
fix
Use require() or use a dynamic import wrapper.
affects: >=1.0.0
deprecatedtv4 and tv4-formats are no longer actively maintained, leading to potential security and compatibility issues.
fix
Consider migrating to a maintained validator like ajv.
affects: >=1.0.0
gotchaIf a schema is not loaded before validate is called, an Error is thrown. This can be confusing if async loading fails silently.
fix
Always check that schemas are loaded via callbacks or promises before calling validate.
affects: >=1.0.0
breakingDependency on request package (used in simple) has been deprecated by npm and may cause installation warnings.
fix
Replace request with a modern HTTP client if using the simple method.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Validator is not a constructor
Using import syntax on a CommonJS default export without appropriate bundler configuration.
fix
Use const Validator = require('json-schema-validator') or configure bundler to handle CommonJS.
Cannot find module 'tv4'
Missing dependency tv4, which is a peer dependency not automatically installed.
fix
Install tv4 explicitly: npm install tv4
Error: Schema for typeId '...' has not been loaded
validate() called before the required schema has finished loading.
fix
Ensure fetchSchemas callback has been invoked before calling validate.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
tv4requiredcore validation engine
tv4-formatsrequiredadditional format validators
Agent activity
6 hits · last 30 days
node
6
Resources
json-schema-validator — npm install json-schema-validator · libregistry