Registry / validation / json-gate

json-gate

JSON →
library0.8.23jsnpmunverified

A friendly, fast JSON schema validator for JavaScript, supporting JSON Schema Draft 3. Current stable version is 0.8.23. The library is minimal and synchronous or asynchronous. It produces detailed, human-friendly error messages. Unlike many modern validators, it only supports Draft 3 (not Draft 4+ or 2020-12), making it a legacy choice. The API is simple: create a schema and validate objects. It is not actively maintained, as the last release was years ago. It has no dependencies.

npm install json-gate
INSTALL
IMPORT
SIG · JSON-GATE
J
json-gate
validationjavascriptv0.8.23
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.

createSchema
import { createSchema } from 'json-gate'
const createSchema = require('json-gate').createSchema
CommonJS require works but ESM import is preferred for modern projects. The default export is not available.
Schema
import { Schema } from 'json-gate'
import Schema from 'json-gate'
Schema is a named export, not default. You can also create schema via createSchema() which returns a Schema instance.
SchemaError
import { SchemaError } from 'json-gate'
const SchemaError = require('json-gate').SchemaError
SchemaError is thrown on validation failure. It is a named export. In TypeScript, you may need to declare types.

Create a schema, validate an object synchronously, and handle errors.

import { createSchema } from 'json-gate'; const schema = createSchema({ type: 'object', properties: { name: { type: 'string', required: true }, age: { type: 'integer', minimum: 0, default: 0 } }, additionalProperties: false }); const input = { name: 'Alice' }; try { schema.validate(input); console.log('Valid!', input); } catch (err) { console.error('Validation failed:', err.message); }
Debug
Known issues
deprecatedjson-gate only supports JSON Schema Draft 3. Draft 4 and later features (e.g., const, if/then/else) are not supported.
fix
Use a modern validator like Ajv or @cfworker/json-schema.
affects: >=0.0.0
gotchavalidate() mutates the input object when 'default' properties are specified.
fix
Clone the input before validating if mutation is undesirable: schema.validate(JSON.parse(JSON.stringify(input))).
affects: >=0.0.0
gotchavalidate() throws an error synchronously but also accepts a callback for async mode. Mixing them can cause confusion.
fix
Choose one mode consistently. If using callback, pass a function as second argument to avoid exceptions being thrown.
affects: >=0.0.0
breakingThe package has no TypeScript definitions. Using with TypeScript requires manual type declarations.
fix
Install @types/json-gate if available (none exist) or create a declaration file.
affects: >=0.0.0
gotchaThe schema object is mutated during validation if it contains 'default' values that are applied.
fix
Deep clone the schema before use if reuse is needed without defaults applied.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: json_gate_1.createSchema is not a function
Default import used when named import is required.
fix
Use import { createSchema } from 'json-gate' instead of import createSchema from 'json-gate'.
SchemaError: JSON object property 'age': value 150 is greater than maximum 120
Input violates schema constraint (maximum).
fix
Ensure input values meet schema requirements.
Error: Schema property 'additionalProperties' is not a boolean
Schema definition has invalid type for reserved keyword.
fix
Set 'additionalProperties' to a boolean or a schema object.
TypeError: schema.validate is not a function
createSchema() was not called correctly, or the schema variable is undefined.
fix
Ensure createSchema() is called with a valid schema object and returns a Schema instance.
Upgrade
Version history
0.8.23latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
26 hits · last 30 days
node
22
Resources
json-gate — npm install json-gate · libregistry