Registry / devops / zod-from-json-schema

zod-from-json-schema

JSON →
library0.5.2jsnpmunverified

A runtime conversion library that creates Zod schemas from JSON Schema definitions, version 0.5.2. Unlike json-schema-to-zod which generates source code, this executes the conversion at runtime, enabling dynamic schema generation. Supports both Zod 3 and Zod 4 (latest) with ESM and CJS. Maintained by Glide Apps with CI and coverage badges. Key differentiator: runtime conversion vs. code generation, allowing use with dynamic or remote schemas.

npm install zod-from-json-schema
INSTALL
IMPORT
SIG · ZOD-FROM-JSON-SCHE
Z
zod-from-json-schema
devopsjavascriptv0.5.2
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.

convertJsonSchemaToZod
import { convertJsonSchemaToZod } from 'zod-from-json-schema'
import convertJsonSchemaToZod from 'zod-from-json-schema'
Named export only; default import is not available.
convertJsonSchemaToZod
const { convertJsonSchemaToZod } = require('zod-from-json-schema')
const convertJsonSchemaToZod = require('zod-from-json-schema')
CommonJS destructured require is required; direct assignment returns undefined.
convertJsonSchemaToZod
import { convertJsonSchemaToZod } from 'zod-from-json-schema'
TypeScript types are included; no separate @types package needed.

Demonstrates runtime conversion of a JSON Schema to a Zod schema and parsing valid data.

import { convertJsonSchemaToZod } from 'zod-from-json-schema'; const jsonSchema = { $schema: "https://json-schema.org/draft/2020-12/schema", type: "object", properties: { name: { type: "string" }, age: { type: "integer", minimum: 0 } }, required: ["name"] }; const zodSchema = convertJsonSchemaToZod(jsonSchema); const result = zodSchema.parse({ name: "Alice", age: 30 }); console.log(result); // { name: 'Alice', age: 30 }
Debug
Known issues
breakingUnsupported JSON Schema features (e.g., $ref, oneOf, if/then/else) may produce unexpected results or throw errors.
fix
Check the documentation for supported keywords; consider flattening references before conversion.
affects: >=0.1.0
deprecatedSupport for Zod 3 is deprecated in favor of Zod 4.
fix
Upgrade to Zod 4 and use the latest zod-from-json-schema version.
affects: >=0.4.0
gotchaThe package does not validate the input JSON Schema itself; malformed schemas may cause silent failures.
fix
Validate your JSON Schema externally using a library like ajv before conversion.
affects: >=0.1.0
breakingChanges in default options (e.g., strict mode) between minor versions may alter behavior.
fix
Pin to a specific minor version and test after upgrades.
affects: >=0.4.0 <0.6.0
Errors
Common errors & fixes
TypeError: convertJsonSchemaToZod is not a function
Using default import instead of named import.
fix
Use import { convertJsonSchemaToZod } from 'zod-from-json-schema'
Error: Unknown keyword 'if'
The JSON Schema uses 'if'/'then'/'else' which is not supported.
fix
Simplify the schema to avoid unsupported keywords, or preprocess with another library.
Module not found: Error: Can't resolve 'zod-from-json-schema'
Package not installed or incorrect import path.
fix
Run npm install zod-from-json-schema and verify import path.
Upgrade
Version history
0.5.2latest on npm
Audit
Dependencies
zodrequiredpeer dependency required to create Zod schemas
Agent activity
28 hits · last 30 days
node
24
Resources
zod-from-json-schema — npm install zod-from-json-schema · libregistry