Zod Overview#
Zod is a TypeScript-first schema validation library.
Why Zod?#
- ✅ TypeScript type inference
- ✅ Runtime validation
- ✅ Zero dependencies
- ✅ Works in Node.js and browsers
Quick Start#
import { z } from 'zod';
// Define a schema
const UserSchema = z.object({
name: z.string(),
age: z.number().min(0),
email: z.string().email(),
});
// Parse data
const user = UserSchema.parse({
name: "John",
age: 30,
email: "john@example.com"
});
// Type is inferred!
type User = z.infer<typeof UserSchema>;