Zod lets you define schemas in TypeScript, parse untrusted input, and get typed, validated results with inferred static types.
Overview
Zod is a validation library centered on TypeScript. You describe shapes—from simple strings to nested objects—and parse data through methods such as parse or safeParse. Successful parsing returns a typed deep clone; failures yield structured ZodError details or a discriminated safeParse result without throwing.
The API is immutable: chaining methods returns new schema instances. It runs in Node.js and modern browsers, ships a small gzipped core, works with plain JavaScript as well as TypeScript, and can emit JSON Schema. An ecosystem of form libraries, API tooling, and adapters builds on it.
For hot paths, optional ahead-of-time compilation via z.compile can speed validation while invalid inputs fall back to the regular parser for consistent errors. Global compilation can be toggled; CSP or jitless environments disable automatic compilation. Types are extracted with z.infer, and separate input/output types exist when transforms change shapes.
The project documents strict TypeScript tsconfig requirements, publishes on npm and jsr, and offers doc search tooling for agents. Maintenance targets recent TypeScript releases.
Key features
- Schema parse and safeParse APIs
- Static types via z.infer
- Structured ZodError reporting
- Optional AOT compile fast path
- JSON Schema conversion
- No runtime dependencies
- Async parse variants
- Large adapter ecosystem
Use cases
- API request and response validation
- Form input checking in TypeScript
- Config and env parsing
- Shared types between client and server