JSON to Zod

Zod schemas and inferred TypeScript types from a JSON sample.

About this tool

Paste JSON and get Zod schemas for runtime validation, plus the matching TypeScript type via z.infer. Options add .int() for whole numbers, .strict() to reject unknown keys, and exports for every schema.

How the Zod is generated

Each JSON object becomes a z.object schema, and nested schemas are defined before the schemas that use them, so the file runs top to bottom. Strings become z.string(), whole numbers z.number().int(), decimals z.number(), booleans z.boolean() and arrays z.array(...). Array items are merged before types are chosen, so a key that only some items have, or that is sometimes null, is treated as optional or nullable rather than breaking decoding. A missing key gets .optional(), a sometimes-null value .nullable(), and an always-null value z.null(). Keys that aren't valid identifiers are quoted. We executed the generated code for the sample against a mock of the Zod API to check the order and structure. Honest limits: the schema matches your sample, not every valid response, so add refinements such as .email(), .url(), .min() or enums yourself. Written for Zod 3. JSON to TypeScript, the JSON Schema generator and the JSON formatter are related.

Frequently asked questions

How do I generate a Zod schema from JSON?

Paste the JSON here and copy the schemas. Use UserSchema.parse(data) to validate.

How do I get the TypeScript type?

The output includes export type User = z.infer<typeof UserSchema>.

What does .strict() do?

It makes parsing fail if the data has keys the schema doesn't list.

Is my JSON uploaded?

No. Everything runs in your browser and nothing is stored or sent.