JSON to Zod Schema
Multi-sample inference, optional vs nullable detection, string format helpers (email / url / uuid / datetime / ip), string + number constraints, z.coerce, sorted keys, named import style, v3 + v4-rc output, and presets for strict APIs vs lenient form data.
JSON input
Paste a payload. Add tabs to feed multiple samples — fields missing from any sample become optional.
Zod schema
Updated live as you edit. Nested objects are hoisted into named sub-schemas.
import { z } from "zod"; export const schema = z.object({ id: z.string().uuid(), email: z.string().email(), username: z.string(), passwordHash: z.string(), age: z.number(), acceptedTerms: z.boolean(), newsletter: z.boolean(), createdAt: z.string().datetime(),}); export type Schema = z.infer<typeof schema>; Options
Shape the generated schema — runtime checks, code style, import shape.
Output
Root export name
Becomes export const <name> = z.object({...}).
Export inferred type
Adds export type <Name> = z.infer<typeof name>.
Zod version
Import style
Detection
Detect string formats
Auto-apply .email() / .url() / .uuid() / .datetime() / .ip().
Detect string length
Add .min()/.max() based on sample lengths.
Detect number range
Add .int(), .positive(), .nonnegative(), .min()/.max() from samples.
Coerce primitives
Use z.coerce.* — useful for query strings and FormData.
Code style
Indent
Quotes
Sort keys alphabetically
Order object keys A→Z in the rendered schema.
Test the schema
Paste the generated code into the Zod playground to validate a value end-to-end without bundling.