Zod Schema Generator
Paste a JSON sample and get a smart Zod schema — not a naive one. It merges every element of an array to infer which fields are truly optional, which are nullable, and which are enums (from repeated string values), detects string formats (email, url, uuid, datetime, date, IPv4), and emits the matching z.infer TypeScript type. A live validator lets you paste a second payload and see exactly which fields would fail, and the whole setup is captured in a shareable URL.
About this ToolHow it works, benefits & use casesTap to collapse
Paste a JSON sample and get a smart Zod schema, not a naive one-to-one translation. The generator merges every element of an array to work out which fields are genuinely optional (missing from some records), which are nullable (seen as null somewhere), and which are enums (a string field that only ever takes a small, repeating set of values). It detects string formats — email, url, uuid, datetime, ISO date and IPv4 — and emits the matching z.infer TypeScript type alongside the schema. A built-in validator lets you paste a second payload and instantly see which field paths would fail, so the tool both generates and checks. Toggle strict objects, primitive coercion, format/enum detection, and switch the output between the Zod schema and a plain inferred TypeScript type. The whole configuration lives in a shareable URL.
How to Use
- 1Paste a JSON object — or better, an array of records — into the input (or load an example).
- 2Name the schema and toggle inference options: format detection, enum detection, strict objects, coercion.
- 3Read the generated Zod schema and the inferred z.infer type; switch the output toggle to see a plain TS type.
- 4Check the confidence card (how many fields, optionals, nullables, enums and formats were inferred).
- 5Paste another JSON value into "Validate a payload" to see exactly which fields pass or fail, then copy or share.
Key Benefits
- Array-sample merging infers truly optional and nullable fields instead of marking everything required
- Enum detection turns a repeated small string set into z.enum([...])
- String-format detection: email, url, uuid, datetime, date and IPv4
- Emits the matching z.infer TypeScript type, or a plain inferred type via the output toggle
- A live validator reports the exact failing field paths for any payload
- Strict-objects, coercion, and format/enum toggles for full control
- Shareable URL captures the JSON, options and output mode
Common Use Cases
- Turning a sample API response into a Zod schema for request/response validation
- Bootstrapping form or env validation from an example payload
- Inferring which fields are optional or nullable from a list of real records
- Deriving a z.enum from a status/role field that only takes a few values
- Confirming a draft schema accepts the payloads you expect and rejects the ones you do not
Zod schema + inferred type
import { z } from 'zod';
export const schema = z.array(z.object({
sku: z.string(),
price: z.number(),
status: z.enum(['active', 'archived']),
tags: z.array(z.string()).optional(),
featured: z.boolean().optional(),
}));
export type Schema = z.infer<typeof schema>;
Validate a payload
JSON sample
Tip: paste an array of records — the more samples, the smarter the optional / nullable / enum inference.
Inference & output
email, url, uuid, datetime…
repeated small string sets
reject unknown keys
z.coerce.*
Why an array sample is worth more
From a single object the tool can only guess every field is required and non-null. Paste an array and it merges all elements: a key missing from any element becomes .optional(), a value seen as null anywhere becomes .nullable(), and a string field with a small set of repeated values becomes a z.enum([...]).
It validates, not just generates
The “Validate a payload” box runs the inferred schema against any JSON you paste and lists the exact failing field paths — so you can confirm the schema accepts what you expect and rejects what you don’t.
Was this tool helpful?
Share Your Experience
Help others discover this tool!
Related tools
- JSON to TypeScriptGenerate TypeScript interfaces from JSON
- JSON FormatterFormat and validate JSON with syntax highlighting
- TypeScript FormatterFormat and beautify TypeScript code
- React Query Hook GeneratorGenerate TanStack Query hooks for data fetching
- Changelog GeneratorGenerate changelog from Git commit history
- Component Name GeneratorTurn a description into ranked, kind-aware component names with a file scaffold and a name validator (casing, collisions, clarity)
From one object the tool can only assume every field is present and non-null. When you paste an array it merges all the elements: any key absent from some element is marked .optional(), any value seen as null anywhere becomes .nullable(), differing numeric types widen to a plain number, and differing primitive types become a z.union. The more representative samples you provide, the more accurate the schema.
A string field is turned into a z.enum only when it takes a small set of distinct values that actually repeat across your samples (by default 2 to 12 distinct values with at least one repeat). That repetition is the signal that the field is a constrained set rather than free-form text. You can turn enum detection off if you would rather keep z.string().

