JSON → Zod
Paste a JSON sample, get a Zod schema. Toggle also infer TS type for type X = z.infer<typeof XSchema>. Toggle strict objects to disallow unknown keys.
Paste JSON.
How to generate Zod
- Paste your JSON.
- Toggle:
- Also infer TS type — adds
type X = z.infer<typeof XSchema>lines. - Strict objects — adds
.strict()to disallow unknown keys. - Optional vs nullable — distinguish from samples with multiple inputs.
- Also infer TS type — adds
- Output appears below. Copy or Download as
.ts.
FAQ
What about z.coerce?
The tool generates plain z.string() / z.number(). If you need to accept stringified numbers (e.g. from URL params), swap in z.coerce.* after generation.
How do I get optional fields?
Provide a second sample with the optional field missing — the schema becomes field: z.string().optional().
Will it work offline?
Yes — inference is local.