JSON Schema to Zod

Paste a JSON Schema and get Zod source code with the matching z.object, string, number and array rules, plus an inferred TypeScript type.

Use the tool

Why this tool exists

If your API contract is a JSON Schema, you probably also want runtime validation in TypeScript, and Zod is a popular way to do that. Rewriting a large schema by hand means translating each keyword and keeping the two in sync.

This converter handles the commonly used subset: types, string formats such as email and uuid, length and numeric bounds, enum and const, anyOf, oneOf and allOf, nullable types, required lists and references into $defs. The output includes an import and a z.infer type alias. Features like conditionals (if, then, else), patternProperties and dynamic references are not converted and degrade to z.any(). Test the generated schema against real samples before relying on it.

How to use it

  1. Paste your JSON Schema into the input.
  2. Set the name of the exported constant.
  3. Copy the Zod code into your project and check it against sample data.

Frequently asked questions

Which keywords are supported?

type, format, minLength, maxLength, pattern, minimum, maximum, exclusive bounds, multipleOf, enum, const, items, prefixItems, properties, required, additionalProperties, anyOf, oneOf, allOf, nullable, description and default.

What happens to unsupported features?

They are skipped or replaced with z.any(), which accepts anything. That keeps the code valid but loosens the check, so review those fields by hand.

How are recursive $refs handled?

A reference that points back to a type already being converted becomes a lazy z.any(), so output stays finite. Rewrite those spots with z.lazy and a proper type if you need strict recursion.

Which Zod version does the code target?

It uses chained methods like .email() and .datetime() that are common in Zod 3. Newer major versions have some changes, so adjust if your compiler complains.