JSON to Zod Schema
Generate a Zod schema and its inferred TypeScript type from a JSON sample, with nested objects, optional keys, nullable fields and integer checks.
Free · No sign-up · Your inputs stay in your browser
Input
Generate a Zod schema from JSON
Output
Zod
469 characters
Whole numbers become z.number().int(), keys missing from some array items .optional(), and nulls .nullable(). Tighten it by hand: .email(), .url() and enums are facts a single sample cannot show.
Runs in this browser. Nothing you paste is sent to a server.
About this tool
Method, assumptions, practical next steps, and limits.
One definition, checked at runtime
A TypeScript type only exists while compiling. A Zod schema checks the data when it arrives, and z.infer gives the static type from the same definition, so the two cannot drift. Parse at the boundary: const user = userSchema.parse(await res.json()) throws if the API sent something else.
Refine the guess
A sample cannot show rules, so add them: z.string().email(), z.enum([...]) for fixed values, .min() and .max() for ranges. safeParse() returns a result instead of throwing, which suits form validation. See the Zod documentation for the full set.