CLI tool for converting Zod schemas to JSON schemas
Top 34.2% on sourcepulse
This library converts Zod schemas into JSON schemas, targeting developers and teams using Zod for data validation and seeking to generate corresponding JSON schemas for API contracts, documentation, or interoperability. It offers extensive customization for various JSON Schema specifications and Zod features.
How It Works
The library parses Zod schema definitions and translates their validation rules, types, and metadata into the JSON Schema format. It handles complex structures like unions, recursive schemas, and custom validation patterns, mapping Zod's expressive API to JSON Schema's declarative syntax. Advanced options allow fine-grained control over reference resolution, error message inclusion, and target specification versions (e.g., OpenAPI 3.0, JSON Schema Draft 7).
Quick Start & Requirements
npm install zod-to-json-schema
or yarn: yarn add zod-to-json-schema
.zodToJsonSchema
from the library and pass your Zod schema.zod
package.Highlighted Details
$ref
s and provides options for $ref
resolution strategies.ajv-errors
.override
and postProcess
callbacks for deep customization of the generated JSON schema.Maintenance & Community
Licensing & Compatibility
Limitations & Caveats
The OpenAI target is experimental. .transform
output types are not reflected, defaulting to the input schema; use effectStrategy: "any"
as a workaround. Zod enum
s are supported for record keys since v3.11.3, but other non-string key types are ignored. Relative JSON pointers are not widely supported by resolvers. The library does not follow semantic versioning, aligning minor versions with Zod's feature parity.
1 month ago
1 week