Zod
TypeScript-first schema validation with automatic type inference. The default pick for validating API inputs, env vars, and form data without writing types twice.
What is Zod?
Zod is a schema validation library for TypeScript where the schema itself is the single source of truth: define a shape once with z.object({...}), and Zod both validates data against it at runtime and infers the matching TypeScript type automatically. That means no more writing a type and a separate validation function that can silently drift out of sync with each other.
Key features
- Automatic TypeScript type inference from schemas, so the type and the runtime validation logic can never disagree
- Composable schema building: objects, unions, arrays, and refinements combine naturally instead of requiring separate validator functions
- Detailed, structured error output that's easy to map to form field errors or API error responses
- Works anywhere TypeScript runs: API route validation, environment variable parsing, form validation, parsing external API responses
- Large ecosystem of integrations (React Hook Form, tRPC, and others) that treat Zod schemas as a first-class input
Who it's for
Essentially any TypeScript project that needs to validate data at a boundary, form input, API request bodies, environment variables, third-party API responses. Hard to think of a TypeScript project that doesn't benefit from it somewhere.
Pricing
Free and open source.