TypeScript to Zod Converter

Runs in browser

Generate Zod schemas from TypeScript interfaces. Supports v3, v4, unions, enums.

Convert TypeScript interfaces and type definitions to Zod validation schemas instantly. Supports Zod v3 and v4, optional fields, union types, enums, arrays, Records, and nested objects.

TypeScript to Zod Converter tool

Zod version:
Export:
import { z } from "zod";

export const userSchema = z.object({
  id: z.number(),
  name: z.string(),
  email: z.string(),
  age: z.number().optional(),
  role: z.enum(["admin", "user", "viewer"]),
  tags: z.array(z.string()),
  address: z.object({
  city: z.string(),
  country: z.string(),
  zip: z.string().optional(),
}),
  createdAt: z.date(),
  metadata: z.record(z.string(), z.unknown()),
  deletedAt: z.date().nullable(),
});

🔒 Runs in your browser · No uploads · Your data never leaves your device

How to use

  1. Paste TypeScript

    Paste interfaces, type aliases, or enums in the left panel.

  2. Choose Zod version

    Select v3 or v4 and whether to export const or use local const.

  3. Copy or download

    Copy the generated schema or download it as a .ts file.

Common use cases

  • Adding runtime validation to existing TypeScript typesConvert TypeScript interfaces to Zod schemas to validate API responses or form data at runtime without rewriting type definitions.
  • Generating Zod schemas for an API endpointPaste request or response TypeScript types to generate matching Zod validation schemas for use in a tRPC or Fastify handler.

Examples

  • User interface

    Convert a User interface to a Zod schema.

    Input
    interface User { id: number; name: string; email: string; }
    Output
    export const userSchema = z.object({ id: z.number(), name: z.string(), email: z.string() });

Frequently asked questions

Does it handle nested objects?
Yes. Inline object types like address: { city: string; zip?: string } are converted to nested z.object() schemas.
What types are not supported?
Generics (e.g. Response<T>), conditional types, and mapped types fall back to z.unknown() with a comment.

Key concepts

Zod
A TypeScript-first schema validation library that infers static types from schema definitions — used for runtime validation of data shapes.
z.object()
The Zod primitive for defining an object schema with typed keys — equivalent to a TypeScript interface at runtime.

You might find these useful too.

More json tools