Generate a Zod schema from sample JSON.
The JSON to Zod generator builds a Zod validation schema from a sample JSON document, together with the matching inferred TypeScript type. It handles nested objects, arrays, nullable and optional values, and lets you choose strict or passthrough handling of unknown keys. It is a quick way to start runtime validation for an API response.
Zod is a TypeScript library for declaring a schema once and using it for both runtime validation and static types. A schema such as z.object({ id: z.number(), name: z.string() }) checks that incoming data has the right shape, and z.infer extracts the matching TypeScript type from it. This matters because TypeScript types vanish at runtime, so data from an API, a form or a file is unchecked until you validate it. The generator inspects a sample, records each value's type, and writes the corresponding Zod calls: z.string(), z.number() (with .int() for whole numbers), z.boolean(), z.array(...) and z.object(...). Keys missing from some objects get .optional(), and null alongside another type gets .nullable(). Unknown-key handling is chosen with .strict() (reject extra keys) or .passthrough() (keep them).
Strict adds .strict() so parsing fails when an object has keys that are not in the schema. Loose adds .passthrough() so unknown keys are accepted and kept in the parsed result.
It was missing from at least one of the objects merged into that part of the schema. If you want it required, remove .optional() from the generated code.
Edit the generated schema, for example change z.string() to z.string().email(). The generator infers only basic types from the sample.
Yes, it adds an exported type using z.infer<typeof YourSchema>, so the type always matches the schema.
No. The schema is generated in the page and the sample is not sent anywhere.