How to convert JSON to Zod
- Paste a JSON object or array, for example a response from the API you are calling.
- Set the name of the root type.
- Copy the generated Zod code into your project.
What you get
- One
z.object()schema per object, declared before the schemas that use it. - A TypeScript type for each schema with
z.infer, so you do not write types twice. - Whole numbers become
z.number().int(); keys missing from some array items get.optional().
Tips for accurate results
The generator only knows the sample you paste. Include arrays with several items and responses where optional fields are present, so it can tell which keys are always there, which can be null and which numbers have decimals.
Frequently asked questions
Is my JSON sent to a server?
No. The code is generated in your browser, so API responses and other private data never leave your device.
Why use Zod instead of plain TypeScript types?
TypeScript types disappear at runtime, so they cannot check data coming from an API. A Zod schema validates the data when it arrives and gives you the type for free with z.infer.
Which Zod version does the output target?
The generated code uses z.object, z.array, z.union, .nullable() and .optional(), which work the same in Zod 3 and Zod 4.
How are null values handled?
A key that is null in some samples and a string in others becomes z.string().nullable(). A key that is always null becomes z.null(); replace it with the real type once you know it.