Registry / testing / z-schema

z-schema

JSON →
library12.3.1jsnpmunverified

Fast, lightweight JSON Schema validator for Node.js and browsers supporting all major drafts from draft-04 through draft-2020-12. Version 12.3.1, maintained actively with regular releases. Key differentiators: TypeScript-first, ESM/CJS/UMD support, synchronous and asynchronous validation modes, safe (non-throwing) API, schema compilation with $ref resolution. Requires Node.js 22+. Full test coverage, CLI tool included. Distinguishes from Ajv by offering throw/safe modes natively and simpler API.

npm install z-schema
INSTALL
IMPORT
SIG · Z-SCHEMA
Z
z-schema
testingjavascriptv12.3.1
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.

ZSchema
import ZSchema from 'z-schema'
const ZSchema = require('z-schema')
ESM-only since v12. Use dynamic import or update to ESM.
ZSchema
const { default: ZSchema } = await import('z-schema')
const ZSchema = require('z-schema').default
For CommonJS projects using dynamic import. require() fails entirely.
ZSchemaSafe
import ZSchema from 'z-schema'; const validator = ZSchema.create({ safe: true })
import { ZSchemaSafe } from 'z-schema'
No named export for safe variant; use create() method.

ESM/TypeScript quickstart: create a validator, validate an object against a schema, handle errors via try/catch.

import ZSchema from 'z-schema'; const validator = ZSchema.create(); try { validator.validate( { name: 'Alice' }, { type: 'object', properties: { name: { type: 'string' } }, required: ['name'] } ); console.log('Valid'); } catch (error) { console.log('Invalid:', error.details); }
Debug
Known issues
breakingrequire('z-schema') now throws ERR_REQUIRE_ESM in Node.js 22+
fix
Use dynamic import: const ZSchema = (await import('z-schema')).default
affects: >=12.0.0
breakingDefault export is no longer a function; use ZSchema.create() instead
fix
Replace new ZSchema() with ZSchema.create()
affects: >=12.0.0
deprecatedOptions like `noTypeless`, `noExtraKeywords` are deprecated since v10
fix
Use strictMode: true instead of manual flags
affects: >=10.0.0
gotchavalidate() throws by default; safe mode requires `safe: true` option
fix
Pass { safe: true } to create() for non-throwing validation
affects: >=1.0.0
gotchavalidate() returns boolean/void; use 'details' on error for error info
fix
Catch ValidateError and read .details array
affects: >=1.0.0
breakingBrowser UMD build path changed to z-schema/umd/ZSchema.min.js
fix
Update script src or use npm CDN with correct path
affects: >=12.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Using require() to import an ES module
fix
Use dynamic import: const ZSchema = (await import('z-schema')).default
TypeError: ZSchema is not a constructor
Trying to instantiate with new ZSchema() instead of ZSchema.create()
fix
Use ZSchema.create() to get a validator instance
Cannot find module 'z-schema'
Package not installed or incorrect import path
fix
npm install z-schema or check import path
ValidateError: data should match format 'email'
Schema uses a format that requires async validation
fix
Create validator with { async: true } and await validate()
Upgrade
Version history
12.3.1latest on npm
Audit
Dependencies
noderequiredNode.js 22+ required
Agent activity
37 hits · last 30 days
node
30
OpenAI (training)
1
Resources
z-schema — npm install z-schema · libregistry