TypeScript

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 Converter

Zod 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 Converter

Zod 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 Converter

Zod 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 Converter

Zod 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 Converter

Use these examples with guides