Package Exports
- zod-to-json-schema
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (zod-to-json-schema) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Zod to Json Schema
Summary
Does what it says on the tin; converts Zod schemas into JSON schemas!
- Supports all relevant schema types, basic string, number and array length validations and string patterns.
- Resolves recursive and recurring schemas with internal
$refs.
Usage:
import { z } from "zod";
import zodToJsonSchema from "zod-to-json-schema";
const mySchema = z.object({
myString: z.string().min(5),
myUnion: z.union([z.number(), z.boolean()]),
});
const jsonSchema = zodToJsonSchema(mySchema, "mySchema");Expected output:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$ref": "#/definitions/mySchema",
"definitions": {
"mySchema": {
"type": "object",
"properties": {
"myString": {
"type": "string",
"minLength": 5
},
"myUnion": {
"type": ["number", "boolean"]
}
},
"additionalProperties": false,
"required": ["myString", "myUnion"]
}
}
}