
Zod
Version 3.23
Last published: 1 week ago
About Zod
Zod is a TypeScript-first schema declaration and validation library. It's designed to be as developer-friendly as possible. Define your schema once, and Zod will validate your data and infer the static TypeScript type. It's great for validating API inputs, form data, and more.
Installation
npm install zodUsage
Define schemas and parse data: `const mySchema = z.string(); mySchema.parse("hello");`
Example Code
import { z } from "zod";
const UserSchema = z.object({
username: z.string().min(3),
email: z.string().email(),
});
try {
const user = UserSchema.parse({ username: "usr", email: "test@example.com" });
console.log(user);
} catch (e) {
console.error(e.errors);
}Tags
TypeScript
Validation
Schema
Data Integrity