What problem does it solve?
Zod provides a TypeScript-first approach to define runtime schemas for validating data and inferring types, addressing the gap between runtime input and static TypeScript types across APIs, forms, and data processing.
Core Features & Use Cases
- Type-safe runtime validation with schemas defined via z.object, z.string, z.number, and other helpers.
- Type inference via z.infer to derive TypeScript types from schemas.
- Flexible parsing options: .parse (throws), .safeParse (returns result), and .parseAsync for async validation.
- JSON Schema generation via z.toJSONSchema for OpenAPI/AI tooling, plus metadata support with .meta().
- Codecs for bidirectional transformations and advanced patterns like recursion and lazy types.
- Use cases include API input validation, form validation, data ingestion pipelines, and contract-driven development.
Quick Start
Define a simple user schema with z.object and validate data using safeParse.