⌘+J

© 2025 Zod


Designed in Earth-616

Build by oeri
Zod

Zod

TypeScript-first Schema Validation

Migration guide

Getting Started


Zod is a TypeScript-first schema validation library designed for simplicity, safety, and composability. With Zod, you can define schemas that validate and transform your data while ensuring type safety at compile-time. Whether you're working on an API, form validation, data parsing, or runtime type checking, Zod makes validation effortless and declarative.


Github X Discord trpc clerk



ClerkClerk



Why Zod?


Zod stands out among validation libraries due to its TypeScript-first approach and seamless developer experience. Here’s why developers love Zod:

Type Safety – Define schemas that automatically infer TypeScript types, eliminating redundant type definitions. Runtime & Compile-Time Validation – Validate data at runtime while enjoying full type safety in development. Fluent API – Compose schemas effortlessly using a chainable and declarative API. Zero Dependencies – Zod is lightweight, fast, and has no external dependencies, making it ideal for both client and server environments. Great DX (Developer Experience) – Clear error messages, powerful inference, and seamless integration with TypeScript. Flexible Parsing & Transformation – Convert data into different formats, add defaults, refine values, and create custom validators. Integration with Ecosystem – Works seamlessly with frameworks like Next.js, Express, tRPC, React Hook Form, and more.




Key Features


Schema Definition

Zod lets you define validation schemas that are both powerful and expressive.

import { z } from "zod";
 
const UserSchema = z.object({
  id: z.number(),
  name: z.string().min(3),
  email: z.string().email(),
  isActive: z.boolean().default(true)
});

Automatic Type Inference

Zod schemas automatically generate TypeScript types without needing explicit type definitions.

type User = z.infer<typeof UserSchema>;

Deeply Nested Objects & Arrays

Zod supports complex nested structures, ensuring type safety at every level.

const ComplexSchema = z.object({
  users: z.array(UserSchema),
  metadata: z.object({ version: z.string(), timestamp: z.date() })
});

Custom Refinements & Transformations

Define custom validation rules or modify values on-the-fly.

const PasswordSchema = z
  .string()
  .min(8, "Password must be at least 8 characters long")
  .refine(password => /[A-Z]/.test(password), {
    message: "Password must contain at least one uppercase letter"
  });

Error Handling

Zod provides rich error messages and easy-to-understand validation failures.

const result = UserSchema.safeParse({ id: "abc", name: "A" });
 
if (!result.success) {
  console.log(result.error.format());
}


Getting Started


Ready to use Zod? Follow the Installation Guide to set up Zod in your project: Go to Installation →

Already familiar with Zod? Explore the API Reference for advanced usage: Go to API Libraries →



Who Uses Zod?


Zod is trusted by thousands of developers and companies worldwide. It's used in web applications, backend services, form validation, and API request validation in Node.js, Next.js, tRPC, and more.

Join the Zod Community and start building safer, more reliable applications today!



Get Involved


Zod is open-source and maintained by the community. You can contribute by submitting issues, creating pull requests, or improving the documentation.

Stay updated with the latest releases and improvements by following Zod on GitHub.



Zod: TypeScript-first schema validation that is simple, powerful, and developer-friendly!