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
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
- Paste or type your JSON Schema into the input box.
- Set a Schema name — this is the exported variable, and its
z.infertype is the PascalCased version (e.g.user→User). - Pick your Zod version — v4 is the default and recommended; v3 emits the older
.ip()string syntax for IPv4/IPv6 formats. - Toggle the
import { z } from "zod"line and thez.infertype alias on or off. - Copy or download the generated
.tsfile — 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
$refresolution — inline references and$defs,definitions, orcomponents/schemasare resolved automatically. Recursive schemas (a tree node, a nested comment thread) becomez.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()).enumandconst— string enums becomez.enum([...]); single constants becomez.literal(...).oneOf/anyOf— becomez.union([...]), or az.discriminatedUnion(...)when every variant carries the samekind-style property.allOf— object schemas are merged into onez.object(); anything else becomesz.intersection(...).- Formats —
email,uuid,uri/url,date-time,date,time,duration,ipv4, andipv6map to the matching Zod string validator. - Constraints —
pattern,minLength/maxLength,minimum/maximum(including exclusive bounds),multipleOf,minItems/maxItems, anduniqueItemsbecome the equivalent.regex(),.min(),.max(),.multipleOf(), and.unique()checks. - Objects —
requiredkeys stay required; everything else becomes.optional().additionalProperties: falseemits.strict(), and a schema inadditionalPropertiesbecomes.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.
Use it from code
From 3 credits per callREST 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_HEREPaste this at any agent connected to the IOTools MCP server, then add your input.