Zod to JSON Schema Converter examples
Use a free browser-only online converter to turn Zod 4 schemas into JSON Schema for Draft 2020-12, Draft 7, AJV, or OpenAPI-compatible output.
Zod object to JSON Schema example
Object fields, email, UUID, enum, optional array, and nullable nested values.
import { z } from "zod";
export const UserSchema = z.object({
id: z.string().uuid(),
email: z.string().email(),
role: z.enum(["admin", "editor", "viewer"]),
tags: z.array(z.string()).optional(),
profile: z.object({
website: z.string().url().nullable(),
}),
});Zod to JSON Schema ConverterZod enum to JSON Schema example
Enum choices, numeric constraints, strict object output, literals, and arrays.
const ProductSchema = z.object({
sku: z.string().min(3),
price: z.number().min(0),
currency: z.literal("USD"),
status: z.union([z.literal("draft"), z.literal("active")]),
variants: z.array(z.object({
id: z.string(),
inventory: z.number().int().nonnegative(),
})),
});Zod to JSON Schema ConverterZod nullable field to JSON Schema example
Use OpenAPI mode to convert nullable fields into OpenAPI 3.0-compatible output.
export const ApiResponseSchema = z.object({
ok: z.boolean(),
data: z.object({
id: z.string(),
nickname: z.string().nullable(),
}).nullable(),
errors: z.array(z.string()).optional(),
});Zod to JSON Schema ConverterZod refine diagnostic example
Custom refine callbacks need a separate runtime validation step because JSON Schema cannot run TypeScript logic.
const PasswordSchema = z.object({
password: z.string().min(12),
confirmPassword: z.string(),
}).refine((value) => value.password === value.confirmPassword, {
path: ["confirmPassword"],
message: "Passwords do not match",
});Zod to JSON Schema ConverterZod transform diagnostic example
Transforms change runtime output and should be reviewed before publishing a portable JSON Schema contract.
const SearchParamsSchema = z.object({
page: z.coerce.number().int().min(1).default(1),
query: z.string().trim().transform((value) => value.toLowerCase()),
});Zod to JSON Schema ConverterUse these examples with guides
Zod to JSON Schema Converter
Use the canonical free online converter for Draft 2020-12, Draft 7, AJV, or OpenAPI-compatible output.
Zod 4 z.toJSONSchema() guide
Convert schemas natively in Zod 4, pick a draft target, add metadata, and migrate off the zod-to-json-schema package.
Zod to OpenAPI guide
Generate Swagger/OpenAPI docs from Zod schemas, compare package workflows, and choose OpenAPI 3.0 or 3.1.
Convert Zod to JSON Schema with AJV
Convert Zod to JSON Schema, choose an Ajv draft, compile validators, and avoid unsupported Zod features.
Fastify Zod validation
Use Zod schemas with Fastify request validation, response schemas, type providers, and OpenAPI output.
Zod to JSON Schema for OpenAPI
Publish OpenAPI-compatible schema output from TypeScript-owned Zod contracts.
Zod refine vs superRefine
Review why custom refinements cannot be represented as plain JSON Schema without a separate validation step.
Zod API schemas
Use Zod at API request and response boundaries before publishing or validating contracts.
Zod vs JSON Schema
Decide when Zod, JSON Schema, OpenAPI, and AJV should own runtime validation contracts.