JSON Schema → Zod
Generate Zod validation schemas from a JSON Schema document. Runtime type safety from your existing schema. 100% local.
How It Works
This tool reads a JSON Schema document and produces ready-to-use Zod validation code. Each object schema becomes a named z.object() variable. $ref references to $defs are resolved to named schema constants. Inferred TypeScript types via z.infer are emitted at the bottom of the output — no need to maintain separate type declarations.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "User",
"description": "A user account",
"type": "object",
"required": ["id", "name", "role"],
"properties": {
"id": { "type": "integer" },
"name": { "type": "string" },
"email": { "type": "string" },
"role": { "type": "string", "enum": ["admin", "editor", "viewer"] },
"address": {
"type": "object",
"required": ["city", "country"],
"properties": {
"city": { "type": "string" },
"country": { "type": "string" }
}
},
"tags": { "type": "array", "items": { "type": "string" } }
}
}import { z } from 'zod';
export const AddressSchema = z.object({
city: z.string(),
country: z.string(),
});
export const UserSchema = z.object({
id: z.number(),
name: z.string(),
email: z.string().optional(),
role: z.enum(["admin", "editor", "viewer"]),
address: z.object({
city: z.string(),
country: z.string(),
}).optional(),
tags: z.array(z.string()).optional(),
});
export type User = z.infer<typeof UserSchema>;Keyword Mapping
| JSON Schema keyword | Zod output | Notes |
|---|---|---|
| type: "string" | z.string() | |
| type: "number" / "integer" | z.number() | Both map to z.number() |
| type: "boolean" | z.boolean() | |
| type: "null" | z.null() | |
| type: "array" + items | z.array(T) | Element type from items |
| type: "object" + properties | z.object({...}) | Named const, hoisted |
| required: ["x"] | x: z.string() | No .optional() |
| (key absent from required) | x: z.string().optional() | .optional() appended |
| enum: ["a","b"] | z.enum(["a","b"]) | All-string enums |
| enum: [1, "x"] | z.union([z.literal(1), z.literal("x")]) | Mixed enums |
| anyOf / oneOf | z.union([...]) | Union of member schemas |
| allOf (objects) | Merged z.object() | Properties combined |
| allOf (mixed) | z.intersection(A, B) | Intersection |
| $ref: "#/$defs/Foo" | FooSchema | Resolved to named const |
| nullable: true | .nullable() | OpenAPI 3.0 extension |
| additionalProperties: true | .catchall(z.unknown()) | Appended to z.object() |
title field when present. If your schema has no title, the “Root schema name” input above the editor is used. The variable will be named {Name}Schema and the inferred type will be named {Name}.$ref and $defs Resolution
Local references (#/$defs/TypeName and #/definitions/TypeName) are resolved to named Zod schema constants. Definitions are emitted before any schema that references them, ensuring the generated code is valid without reordering.
#/ are resolved. Inline the referenced definitions into your $defs section before pasting.Try It
Frequently Asked Questions
Your files stay on your computer. Dad promised.