JSON to Zod Schema Converter
Turn a JSON sample into a Zod schema and its inferred TypeScript type for validating API data at runtime.
How to generate a Zod schema from JSON
Paste your JSON sample
Paste or type it into the box, or press Try an example. Use a real response that has every field you expect.
Name the main type
Name the schema: it is also the name of its type.
Check the Zod output
Nested objects become their own types. Rename fields or mark optional ones to suit your API.
A field missing from your sample will be missing from the result.
Use it in your project
Paste the schema into your validation code.
Worked example
This is what JSON to Zod Schema Converter gives for its own sample values. Open the tool above and change anything to try your own.
JSON sample
{
"id": 42,
"user-name": "ada",
"score": 9.5,
"active": true,
"tags": ["admin", "beta"],
"address": { "city": "London", "zip": "N1 9GU" },
"orders": [
{ "sku": "A-1", "qty": 2, "coupon": "SAVE10" },
{ "sku": "B-7", "qty": 1 }
]
}- Name of the main type
- Root
Zod schema
import { z } from "zod";
export const addressSchema = z.object({
city: z.string(),
zip: z.string(),
});
export type Address = z.infer<typeof addressSchema>;
export const orderSchema = z.object({
sku: z.string(),
qty: z.number().int(),
coupon: z.string().optional(),
});
export type Order = z.infer<typeof orderSchema>;
...About JSON to Zod Schema Converter
Turn a JSON sample into a Zod schema plus the TypeScript type inferred from it, so API data can be checked at runtime instead of trusted. Missing fields become optional and nulls become nullable.
FAQs
Does it install anything?
No. It writes the code. Add the zod package to your project to use it.
How are optional fields handled?
A field missing from some items in a list gets .optional().
Can I get plain types instead?
Use JSON to TypeScript Converter.