Generate a Zod schema from JSON
Zod gives you runtime validation and a static TypeScript type from one schema definition, but writing the schema to match a JSON payload by hand is slow. This tool infers a ready-to-use Zod schema plus its inferred type from a representative JSON sample.
How it works
The generator walks the sample and maps each value to a Zod validator:
| JSON | Zod |
|---|---|
| string | z.string() |
| number | z.number() |
| boolean | z.boolean() |
| null | z.null() |
| object | z.object({ ... }) |
| array of T | z.array(T) |
| mixed array | z.array(z.union([...])) |
| empty array | z.array(z.unknown()) |
It also exports a matching TypeScript type via z.infer<typeof schema>, so you
get validation and a static type from one definition.
Example
This JSON:
{ "id": 7, "tags": ["a", "b"] }
generates:
const schema = z.object({
id: z.number(),
tags: z.array(z.string()),
});
type Schema = z.infer<typeof schema>;
Because the schema is inferred from one sample, add .optional() or
.nullable() where your real data needs it. All inference happens in your
browser — your JSON is never uploaded or stored.