EN
My tools

JSON to Zod Schema Generator

Generate a Zod schema from JSON: z.object, arrays, optional and nullable fields, unions for mixed values, email/url/uuid/datetime checks and z.infer types.

Zod schema
Named schemas
1

Use it as User.parse(data) (throws on invalid data) or User.safeParse(data).

A key missing from some array items becomes .optional(); a null value becomes .nullable(). A number written as 10.0 counts as a whole number, so add a sample with a fraction if the field can have one.

My tools →
Advertisement

Zod validates data at run time and gives you the TypeScript type for free, but writing a schema for a large API response by hand is tedious. Paste a sample and this tool writes the schema: z.object for objects, z.array for lists, .optional() for keys missing in some items, .nullable() for nulls, unions where values differ, and string checks such as email, URL, UUID, date and ISO date-time when every sample matches. It ends with the matching z.infer type.

How to use this tool

  1. Paste a representative JSON sample — several array items give better results.
  2. Name the schema and choose Zod 3 or Zod 4 syntax.
  3. Decide on format detection, .int() for whole numbers and strict objects.
  4. Copy the code into a .ts file; use Schema.parse(data) or safeParse.

Formula

string → z.string() · number → z.number() (.int() for whole numbers) · boolean → z.boolean() · [ … ] → z.array() · { … } → z.object() · missing → .optional() · null → .nullable()

All samples at the same place are combined: whole and fractional numbers give z.number(); different kinds give z.union([...]); a key present in only some array items is optional. A string check (email, URL, UUID with a version and variant, date, ISO date-time with or without an offset) is added only if every sample at that place passes it, so the schema accepts the data it was made from. Zod 4 uses its top-level forms (z.email(), z.iso.datetime(), z.strictObject).

Example

The sample user becomes a z.object with id: z.number().int(), email: z.string().email(), website: z.string().url(), createdAt: z.string().datetime({ offset: true }), score: z.number(), tags: z.array(z.string()), an address object and orders: z.array(z.object({ id: z.string().uuid(), total: z.number(), coupon: z.string().optional() })) — coupon is optional because only one order has it — and nickname: z.null().

Frequently asked questions

Zod 3 or Zod 4?

Zod 4 moved string formats to top-level functions (z.email(), z.uuid(), z.iso.datetime()) and recommends z.strictObject over .strict(). Pick the version your project installs; the rest of the schema is the same.

Why is a field z.null()?

Every sample had null there, so the real type is unknown. Replace it with, for example, z.string().nullable().

Will the schema accept my sample?

Yes — formats are only added when all sample values pass them, and optional/nullable follow the samples. One exception, noted when it happens: an optional key named like a built-in object property (constructor, toString, __proto__) is looked up through the prototype by Zod, so items without it are rejected. Other data may still need adjustments.

Is my JSON uploaded?

No. The schema is generated in your browser.

Sources

Last updated:

Cite or embed this tool
APA

kakaoCalc. (2026, November 8). JSON to Zod Schema Generator. https://kakao.mobile/tools/json-to-zod-schema/

MLA

“JSON to Zod Schema Generator.” kakaoCalc, 8 Nov. 2026, kakao.mobile/tools/json-to-zod-schema/.

Paste this code into your page. The widget runs in your visitors' browsers, shows no ads and keeps a link back to this page. Embedding terms

Advertisement