Skip to main content

JSON Schema to Zod Schema Converter

Convert a JSON Schema (Draft 7, 2019-09, or 2020-12) into a ready-to-use Zod validation schema in TypeScript. Resolves $refs (including recursive ones), oneOf/allOf/anyOf, nullable fields, format keywords, and required/optional properties, and shows the inferred TypeScript type.

Input

 

Exported variable name for the root schema (its z.infer type is PascalCased).

Output

Zod schema
 
Inferred TypeScript type
 
Was this helpful?

Guides

Convert a JSON Schema into a ready-to-use Zod validation schema in TypeScript. Paste a Draft 7, 2019-09, or 2020-12 schema and get the matching z.object({ ... }) code, plus the statically-inferred TypeScript type — no hand-typing required.

Hand-writing a Zod schema from a JSON Schema is tedious and error-prone: every $ref needs resolving, every required key needs an .optional(), and every oneOf needs a union. This tool does that deterministically, so the result is correct every time — no hallucinated property, no missed nullable.

How to use it

  1. Paste or type your JSON Schema into the input box.
  2. Set a Schema name — this is the exported variable, and its z.infer type is the PascalCased version (e.g. userUser).
  3. Pick your Zod version — v4 is the default and recommended; v3 emits the older .ip() string syntax for IPv4/IPv6 formats.
  4. Toggle the import { z } from "zod" line and the z.infer type alias on or off.
  5. Copy or download the generated .ts file — the Zod schema on one tab, the inferred TypeScript type on the other.

The output updates automatically as you type, so you can tweak the schema and watch the code change live.

What it converts

  • $ref resolution — inline references and $defs, definitions, or components/schemas are resolved automatically. Recursive schemas (a tree node, a nested comment thread) become z.lazy(() => ...), so even self-referencing data round-trips correctly.
  • type — strings, numbers, integers, booleans, null, objects, and arrays, including Draft 7's array-of-types form (["string", "null"] becomes .nullable()).
  • enum and const — string enums become z.enum([...]); single constants become z.literal(...).
  • oneOf / anyOf — become z.union([...]), or a z.discriminatedUnion(...) when every variant carries the same kind-style property.
  • allOf — object schemas are merged into one z.object(); anything else becomes z.intersection(...).
  • Formatsemail, uuid, uri/url, date-time, date, time, duration, ipv4, and ipv6 map to the matching Zod string validator.
  • Constraintspattern, minLength/maxLength, minimum/maximum (including exclusive bounds), multipleOf, minItems/maxItems, and uniqueItems become the equivalent .regex(), .min(), .max(), .multipleOf(), and .unique() checks.
  • Objectsrequired keys stay required; everything else becomes .optional(). additionalProperties: false emits .strict(), and a schema in additionalProperties becomes .catchall(...).

What about not?

The not keyword has no direct Zod equivalent, so the tool drops it and leaves a comment in the generated code. The rest of the schema converts normally.

Is my data uploaded anywhere?

No. Everything runs entirely in your browser. Your JSON Schema is parsed and converted locally — nothing is sent to a server, and nothing is stored. You can convert confidential API contracts with confidence, and the tool keeps working offline once the page has loaded.

Related tools

If you have a JSON sample (actual data) instead of a JSON Schema, use the JSON to Zod Schema Generator to infer a schema from the values. To validate data against a schema instead of generating one, try the JSON Schema Validator. For formatting or beautifying raw JSON, see the JSON Formatter.

json-schemazodtypescriptvalidationschemavalidatorcodegenopenapiapi schema

Use it from code

From 3 credits per call

REST API

curl -X POST https://api.iotools.cloud/v1/tool/json-schema-to-zod-schema-converter \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "schemaText": "{\n  \"$schema\": \"http://json-schema.org/draft-07/…",
    "schemaName": "schema",
    "zodVersion": "v4",
    "includeImport": "true",
    "inferType": "true",
    "includeDescriptions": "false"
  }'

Swap in your own key from your account. The tool's fields are the body — no wrapper.

Ask an AI agent

Use the IOTools `json-schema-to-zod-schema-converter` tool (JSON Schema to Zod Schema Converter) on this input:

YOUR_INPUT_HERE

Paste this at any agent connected to the IOTools MCP server, then add your input.

Love the tools? Lose the ads.

One payment clears every ad from your account, for good. No subscription, no tracking.