Registry / testing / z-schema-errors

z-schema-errors

JSON →
library0.2.1jsnpmunverified

z-schema-errors normalizes error messages from Z-Schema JSON Schema validation reports. It transforms nested property paths (e.g., '#/items/[0]' → 'items[0]'), extracts first array params, and allows custom message formatting using macros like {message}, {path}, {description}, and {params[i]}. Supports global context messages and custom extractors for each macro. Version 0.2.1 is the latest; no recent updates. As a thin wrapper around Z-Schema, it only works with that validator. No TypeScript types are provided, and it uses CommonJS.

npm install z-schema-errors
INSTALL
IMPORT
SIG · Z-SCHEMA-ERRORS
Z
z-schema-errors
testingjavascriptv0.2.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.

init
const ZSchemaErrors = require('z-schema-errors'); const reporter = ZSchemaErrors.init();
import { init } from 'z-schema-errors';
Package is CommonJS-only; ESM syntax will fail. Use require().
ZSchemaErrors (default)
const ZSchemaErrors = require('z-schema-errors');
const ZSchemaErrors = require('z-schema-errors').default;
No .default property; the module exports the init function directly as the module.exports.
reporter
const reporter = ZSchemaErrors.init(options);
const reporter = new ZSchemaErrors(options);
init() is a factory function, not a constructor. Do not use new.

Shows basic usage: validate JSON with Z-Schema, then use z-schema-errors to generate a human-readable error message.

const ZSchema = require('z-schema'); const ZSchemaErrors = require('z-schema-errors'); const validator = new ZSchema(); const reporter = ZSchemaErrors.init(); const json = { name: 'Alice' }; const schema = { type: 'object', properties: { age: { type: 'integer' } }, required: ['age'] }; const isValid = validator.validate(json, schema); if (!isValid) { const errorMessage = reporter.extractMessage({ report: validator.lastReport }); console.log(errorMessage); } // Output: "An error occurred 'Missing required property: age' on property # (Object instance has properties which are not allowed by the schema)."
Debug
Known issues
gotchaThe extractMessage method expects an object with a 'report' property, not the raw error array.
fix
Use reporter.extractMessage({ report: validator.lastReport }) instead of reporter.extractMessage(validator.lastReport.errors).
affects: >=0.0.0
deprecatedThe package has not been updated since 2015 and may not support newer Z-Schema versions.
fix
Consider migrating to ajv-errors or manually formatting Z-Schema errors.
affects: >=0.0.0
gotchaCustom format strings must include existing macros; unknown macros are left as-is.
fix
Stick to the documented macros: {message}, {path}, {description}, {params[i]}, {contextMessage}.
affects: >=0.0.0
gotchaThe 'params' macro only works with the first nested array in the error's params field.
fix
If your schema errors have complex params, verify the output; consider custom extractors.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: ZSchemaErrors.init is not a function
Using import { init } from 'z-schema-errors' (ESM) instead of require.
fix
Use const ZSchemaErrors = require('z-schema-errors'); then ZSchemaErrors.init();
TypeError: Cannot read property 'map' of undefined
Passing validator.lastReport.errors directly to extractMessage instead of { report: validator.lastReport }.
fix
Call reporter.extractMessage({ report: validator.lastReport })
Cannot find module 'z-schema'
z-schema is a peer dependency but not installed.
fix
Run npm install z-schema
Upgrade
Version history
0.2.1latest on npm
Audit
Dependencies
z-schemarequiredpeer dependency: this library processes error reports from Z-Schema validator instances.
Agent activity
38 hits · last 30 days
node
32
OpenAI (training)
1
Resources
z-schema-errors — npm install z-schema-errors · libregistry