Dad’s Data formats tools

JSON Schema → Zod

Generate Zod validation schemas from a JSON Schema document. Runtime type safety from your existing schema. 100% local.

JSON Schema Input
Root schema name(used when schema has no title)
Zod Schema Output
Paste a JSON Schema to generate a Zod schema.

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.

Input
{
  "$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" } }
  }
}
Output
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 keywordZod outputNotes
type: "string"z.string()
type: "number" / "integer"z.number()Both map to z.number()
type: "boolean"z.boolean()
type: "null"z.null()
type: "array" + itemsz.array(T)Element type from items
type: "object" + propertiesz.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 / oneOfz.union([...])Union of member schemas
allOf (objects)Merged z.object()Properties combined
allOf (mixed)z.intersection(A, B)Intersection
$ref: "#/$defs/Foo"FooSchemaResolved to named const
nullable: true.nullable()OpenAPI 3.0 extension
additionalProperties: true.catchall(z.unknown())Appended to z.object()
Tip: The root schema name comes from the schema's 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.

Warning: Remote $ref URIs are not supported. Only document-local references starting with #/ are resolved. Inline the referenced definitions into your $defs section before pasting.

Try It

Interactive — edit the input to see the output update
Try it
Result

Frequently Asked Questions

Your files stay on your computer. Dad promised.

Data formats tools

Search the Data formats tools