JSON to Zod
Paste a JSON sample to get a Zod 4 schema: z.object, z.array, .optional() and .nullable() fields, plus the TypeScript type with z.infer.
How to generate a Zod schema from JSON
- Paste a JSON sample on the left or open a .json file; the Zod code appears on the right.
- Name the schema and choose whether to export it, block extra fields or add the TypeScript type.
- Copy it or download the .ts file and paste it into your project.
Frequently asked questions
Zod 4 (it uses z.int() and z.strictObject). Most of it also runs on Zod 3 except z.int() — change it to z.number().int() if you are still on Zod 3.
.optional() when the field is only in some objects of an array; .nullable() when its value is sometimes null.
It uses z.strictObject instead of z.object, so data with a field that is not in the sample fails instead of having the field silently dropped.
A field with only whole numbers is z.int(); one with decimals like 9.5 is z.number(). Very large integers (such as 19-digit IDs) also get z.number(), because JavaScript cannot hold them exactly.
There is nothing to learn from, so they become z.array(z.unknown()). Paste a sample with data or edit it by hand.
It is completely free and needs no sign-up.
Related tools
JSON to TypeScriptGenerate TypeScript interfaces from sample JSONJSON to JSON SchemaGenerate a JSON Schema from a JSON sampleJSON to Go structGenerate Go structs from a JSON sampleJSON to Python dataclassGenerate dataclasses or Pydantic models from JSONJSON to Java classGenerate Java classes or records from JSONJSON to Kotlin data classGenerate Kotlin data classes from a JSON sampleJSON Escape / UnescapeTurn text into a valid JSON string and backJSON FormatterFormat, minify and validate JSONJSON RepairAutomatically fix broken JSON