Registry / devops / json-schema-to-zod

json-schema-to-zod

JSON →
library2.8.1jsnpmunverified

Converts JSON Schema (draft 4+) objects or files into Zod schemas as JavaScript/TypeScript code. Current stable version is 2.8.1. Release cadence is irregular with maintenance mode. Key differentiators: supports Zod v3 and v4 output, CLI and programmatic usage, zero runtime dependencies (formatting and ref resolution delegated to external tools since v2). Deprecated as of March 2026.

npm install json-schema-to-zod
INSTALL
IMPORT
SIG · JSON-SCHEMA-TO-ZOD
J
json-schema-to-zod
devopsjavascriptv2.8.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.

jsonSchemaToZod
import { jsonSchemaToZod } from 'json-schema-to-zod'
const jsonSchemaToZod = require('json-schema-to-zod')
ESM default. CommonJS require works in Node.js but not in browser environments without bundling. Since v2, the package is ESM-first.
jsonSchemaToZod
const { jsonSchemaToZod } = require('json-schema-to-zod')
import jsonSchemaToZod from 'json-schema-to-zod'
For CommonJS environments. Note that default import from CJS is a named export; the default import pattern is incorrect.
type JsonSchemaToZodOptions
import type { JsonSchemaToZodOptions } from 'json-schema-to-zod'
import { JsonSchemaToZodOptions } from 'json-schema-to-zod'
Option type is exported as a type-only export. Use type import to avoid runtime import in TypeScript when using isolatedModules.

Converts a simple JSON Schema object to a Zod schema string using programmatic API.

import { jsonSchemaToZod } from 'json-schema-to-zod'; const mySchema = { type: 'object', properties: { name: { type: 'string' }, age: { type: 'integer', minimum: 0 }, }, required: ['name'], }; const zodCode = jsonSchemaToZod(mySchema, { module: 'esm' }); console.log(zodCode); // Output: // import { z } from 'zod'; // export const schema = z.object({ name: z.string(), age: z.number().int().min(0).optional() });
Debug
Known issues
deprecatedPackage is deprecated as of March 2026. No further updates or bug fixes will be provided.
fix
Consider migrating to alternative libraries or maintain a fork. For JSON Schema to Zod conversion, the package remains functional but unmaintained.
affects: >=0.0.0
breakingSince v2, prettier and json-refs are no longer bundled. Output is unformatted and $refs are not resolved automatically.
fix
Pipe output through prettier and resolve $refs with json-refs separately: json-refs resolve schema.json | json-schema-to-zod | prettier --parser typescript > output.ts
affects: >=2.0.0
gotchaDefault zodVersion is 4 (since v2.5.0). If your project uses Zod v3, generated schemas may use APIs not available in v3.
fix
Pass option { zodVersion: 3 } or use CLI flag --zodVersion 3 to generate Zod v3 compatible code.
affects: >=2.5.0
gotchaDepth option defaults to 0, meaning no recursion. Recursive schemas will be truncated to z.any() at the first recursive reference.
fix
Increase depth with e.g., { depth: Infinity } or a specific number to handle recursive schemas.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'zod' or its corresponding type declarations.
Generated code imports zod but zod is not installed in the project.
fix
Install zod as a dependency: npm install zod
TypeError: jsonSchemaToZod is not a function
Using default import in ESM context but package only exports named export.
fix
Use named import: import { jsonSchemaToZod } from 'json-schema-to-zod'
Error: JSON Schema not provided. Use --input flag or pipe JSON.
Running CLI without input (neither piped data nor --input file).
fix
Provide input via piped JSON or use -i flag: json-schema-to-zod -i schema.json
SyntaxError: Unexpected token 'o' (JSON.parse error)
Input file is not valid JSON or contains trailing characters.
fix
Ensure input file is valid JSON. Use a linter or validator to check syntax.
Upgrade
Version history
2.8.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
json-schema-to-zod — npm install json-schema-to-zod · libregistry