DevBolt
Processed in your browser. Your data never leaves your device.

JSON Schema to Zod Converter Online

Paste a JSON Schema and instantly generate Zod validation code. Handles $ref references, composition keywords (allOf, oneOf, anyOf), enums, format constraints, and required/optional field mapping.

← Back to tools

JSON to Zod Converter

Convert JSON or JSON Schema to Zod validation schemas. Supports $ref, allOf/oneOf/anyOf, enum, format constraints, and nested objects.

Input:

About JSON to Zod Converter

  • Two input modes — paste raw JSON data to infer schemas, or paste a JSON Schema for precise conversion with $ref, allOf/ oneOf/ anyOf, and constraints.
  • JSON Schema support — converts required, enum, const, format (email, uri, uuid, date-time, ipv4, ipv6), pattern, minimum/maximum, minLength/maxLength, default, and $defs/definitions.
  • Smart inference — detects emails, URLs, UUIDs, and ISO dates in raw JSON values and adds appropriate Zod refinements.
  • Required vs optional — JSON Schema required arrays map to required fields; all others get .optional().
  • TypeScript type — generates z.infer<typeof schema> so you get TypeScript types for free.
  • Everything runs in your browser — no data is sent over the network.

Why convert JSON Schema to Zod?

JSON Schema is the industry standard for describing JSON data structures, used in OpenAPI specs, configuration files, and API documentation. Zod is the dominant runtime validation library in TypeScript with 90M+ weekly npm downloads. Converting JSON Schema to Zod gives you compile-time types AND runtime validation from a single source of truth — eliminating the drift between your schema definitions and TypeScript types.

Supported JSON Schema features

This converter handles the most commonly used JSON Schema keywords: type (string, number, integer, boolean, null, object, array), properties and required, $ref with $defs/definitions resolution, allOf (intersection), oneOf/anyOf (union), enum and const, format (email, uri, uuid, date-time, date, ipv4, ipv6), pattern (regex), minimum/maximum, exclusiveMinimum/exclusiveMaximum, minLength/maxLength, minItems/maxItems, default values, description, nullable, and additionalProperties.

How $ref resolution works

Local $ref pointers like #/$defs/Address or #/definitions/Project are resolved to separate named Zod schemas. The converter generates each referenced schema as its own const variable and references it by name in parent schemas. This produces clean, readable code that mirrors your JSON Schema's structure rather than inlining everything into a single massive schema.

Frequently Asked Questions

Does this tool handle $ref and allOf/oneOf/anyOf from JSON Schema?

Yes. Local $ref pointers within $defs or definitions are resolved to named Zod schemas. allOf maps to z.intersection(), while oneOf and anyOf map to z.union(). Nested compositions are fully supported.

How are required and optional fields handled?

Fields listed in the JSON Schema required array become required Zod fields. All other properties get .optional() appended automatically. You can also toggle the global .optional() checkbox to make all fields optional regardless of the schema.

What JSON Schema draft versions are supported?

The converter supports Draft-07 and Draft 2020-12 keywords including $defs (2020-12) and definitions (Draft-07). Most JSON Schema features used in practice are covered.

Related Convert Tools