JSON to Zod Schema
Validate API responses and form data at runtime without writing schemas by hand. Paste an example and get a Zod schema for every nested object, plus the TypeScript type inferred from each.
How to generate a Zod schema from JSON
- 1Paste a JSON example, ideally with several array items.
- 2Name the root schema.
- 3Copy the code into your project, or download schema.ts.
How the types are worked out
Every item of an array is merged into one type, so a key that's missing from some items becomes optional and a value that's sometimes null becomes nullable. Whole numbers and decimals are told apart, nested objects get their own named types (an “items” array gets an “Item” type), and objects with the same shape share one type.
Zod specifics
Nested schemas are defined first, so the file runs top to bottom. Whole numbers use z.number().int(), optional keys .optional(), nullable values .nullable(), and each schema comes with an export type built with z.infer.
Make it stricter
The schema accepts what your example shows. Add rules like .email(), .min() or .max() where your data needs them.
Frequently asked questions
- Is my data uploaded?
- No. Everything runs in your browser, so the JSON never leaves your device.
- Which Zod version is it for?
- The schemas use the core API (z.object, z.array, z.string and friends), which works in Zod 3 and Zod 4.
- Do I need to install anything?
- Your project needs the zod package: npm install zod.