Skip to content
AZ Tools

JSON to Zod Schema Generator

Turn a JSON object into a Zod validation schema with inferred types, in your browser.

Zod schema

How to use

  1. Paste or type your JSON into the input box.
  2. Optionally rename the exported schema constant (defaults to schema).
  3. Copy the generated Zod schema from the output box.

About this tool

Show

Paste any JSON object or array and get a ready-to-use Zod schema with nested objects inlined, so you can validate an API response or a form payload in TypeScript and infer the type from the schema instead of writing it twice. Strings, numbers, and booleans map directly, arrays are typed from their first element, and an empty array becomes an array of unknown. Two spots need your judgement afterwards. A JSON null generates z.null(), which accepts only null — what you usually want is the real type with .nullable() on it. And every key is generated as required, because the sample cannot show which fields the server may leave out, so add .optional() where it applies. Everything runs locally in your browser — your JSON is never uploaded.

Frequently asked questions

How are types inferred?

Strings map to z.string(), numbers to z.number(), booleans to z.boolean(), objects to z.object(), and arrays to z.array() of the first element's type.

What happens with null or empty arrays?

null maps to z.null() and an empty array to z.array(z.unknown()), since the element type can't be inferred from an empty sample.

Does it support nested objects?

Yes. Nested objects are inlined as nested z.object(...) calls, so the whole schema is a single expression you can assign to one constant.

Is my JSON sent anywhere?

No. Conversion happens entirely in your browser; nothing is uploaded.

Should I really keep z.null() for a nullable field?

Almost never. z.null() accepts only null and rejects the actual value, so it is right just for a field that is always null. What you usually want is the real type with .nullable() on it, or .nullish() when the key can also be missing entirely.

Can I get a TypeScript type out of this?

Yes, and that is the reason to use Zod rather than a hand-written interface: z.infer<typeof schema> derives the type from the schema, so validation and types cannot drift apart. Write the schema once and let the type follow it.

Related tools