JSON to Zod Schema

Generate a Zod validation schema from a JSON sample.

Ad placeholder (leaderboard)
Enjoying the tools? Go Pro for £4.99 (one-time) and remove all ads — forever, on this device. Remove ads — £4.99

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:

JSONZod
stringz.string()
numberz.number()
booleanz.boolean()
nullz.null()
objectz.object({ ... })
array of Tz.array(T)
mixed arrayz.array(z.union([...]))
empty arrayz.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.

Ad placeholder (rectangle)