How to use the JSON to Zod Schema Converter
- Paste JSON into the left box, or click Load sample.
- Pick Zod v4 or v3, and set the Root name.
- Keep detect email, URL, UUID, dates on to get
z.email(),z.iso.datetime()and friends instead of plain strings. - Click Copy and paste the schema into your project. Use
RootSchema.parse(data)to validate.
Why use Zod instead of plain TypeScript types?
TypeScript types disappear when your code is compiled, so they can't check what an API, a form or a config file actually sends you at runtime. A Zod schema does both: schema.parse(data) throws a clear error when the data doesn't match, and z.infer<typeof schema> gives you the TypeScript type from the same source, so the two can never drift apart. If you only need types, use JSON to TypeScript.
How the schema is inferred
- Numbers: whole numbers become
z.int()(v4) orz.number().int()(v3); anything with decimals becomesz.number(). - Strings with a format: if every sample value is an email, URL, UUID, ISO date or ISO date-time, you get the matching validator. Turn the option off for plain
z.string(). - null: a key that's sometimes
nullgets.nullable(). A key that's missing from some array items gets.optional(). - Arrays: every item is checked, so mixed arrays become
z.union([...]), and objects inside arrays are merged into one schema. - Order: nested schemas are declared before the schemas that use them, so the file runs as is. Objects with exactly the same shape share one schema.
Zod 4 or Zod 3?
Zod 4 (released in 2025) moved string formats to the top level, such as z.email() and z.uuid(), and added z.int() and z.strictObject(). The old z.string().email() style still works in Zod 4 but is deprecated. Pick v3 if your project hasn't upgraded yet.
Example
import { z } from "zod";
export const customerSchema = z.object({
id: z.int(),
email: z.email(),
phone: z.string().nullable(),
});
export type Customer = z.infer<typeof customerSchema>;
Frequently asked questions
Is the schema exactly right for my API?
It's only as good as your sample. A field that's always present in the sample might be optional in real data, and one that's always a string might sometimes be null. Paste an array of several varied responses for a more accurate schema, then review it.
Why is a field z.null()?
Every value it had in your sample was null, so the real type couldn't be seen. Replace it with the expected type, for example z.string().nullable().
What does strict objects do?
It rejects keys that aren't in the schema instead of quietly removing them: z.strictObject() in v4, .strict() in v3.
Does it work for JSON Schema too?
No, this tool writes Zod code. Zod 4 can turn a schema into JSON Schema with z.toJSONSchema().
Is my JSON uploaded?
No. The schema is generated in your browser.
Updated