JSON Schema to Zod

Paste a JSON Schema and get a Zod schema back. The static type and the runtime parser come from the same source contract — useful for OpenAPI components.schemas, MCP tool inputs, or any JSON Schema you need to validate at a boundary.

JSON input valid
Zod output

      
    

About this conversion

JSON Schema describes the contract; Zod enforces it at runtime. Pasting a schema you got from an OpenAPI spec, an MCP tool definition, or an internal API document into this page gives you a Zod schema that parses any payload claiming to match — at the network boundary, in a webhook handler, or inside a CI smoke test. Pair the result with z.infer<typeof Schema> and you get a TypeScript type for free, identical to what the json-schema-to-typescript page would emit.

The conversion handles type (single value or array union → z.union), properties + required (required becomes non-optional, the rest gets .optional()), items (z.array(...)), enum (all-string → z.enum, mixed → z.union of z.literal, single → z.literal), and local $ref via #/definitions, #/$defs, or #/components/schemas. Definitions are emitted before the root in the output so the const declarations resolve in JS evaluation order — no temporal-dead-zone surprises when you import the generated file.

Why Zod for runtime validation when ajv already validates JSON Schema directly? Two reasons: (1) Zod gives you the TypeScript type and the validator from one source — fewer artifacts, less drift, and the type narrows automatically inside .safeParse success branches. (2) Most TypeScript codebases already carry Zod for forms / tRPC / API input — adding ajv just for JSON Schema doubles the validator footprint. The same conversion is available as an HTTP API at /api/convert — pass {"schema": "<stringified-schema>", "mode": "zod"}.

Same shape, other validators

Other JSON shapes