✨ https://zod.dev ✨
TypeScript-first schema validation with static type inference
These docs have been translated into Chinese.
- Table of contents
- Introduction
- Installation
- Basic usage
- Primitives
- Coercion for primitives
- Literals
- Strings
- Numbers
- BigInts
- NaNs
- Booleans
- Dates
- Zod enums
- Native enums
- Optionals
- Nullables
- Objects
- Arrays
- Tuples
- Unions
- Discriminated unions
- Records
- Maps
- Sets
- Intersections
- Recursive types
- Promises
- Instanceof
- Functions
- Preprocess
- Custom schemas
- Schema methods
- Guides and concepts
- Comparison
- Changelog
Zod is a TypeScript-first schema declaration and validation library. I'm using the term "schema" to broadly refer to any data type, from a simple string
to a complex nested object.
Zod is designed to be as developer-friendly as possible. The goal is to eliminate duplicative type declarations. With Zod, you declare a validator once and Zod will automatically infer the static TypeScript type. It's easy to compose simpler types into complex data structures.
Some other great aspects:
- Zero dependencies
- Works in Node.js and all modern browsers
- Tiny: 8kb minified + zipped
- Immutable: methods (e.g.
.optional()
) return a new instance - Concise, chainable interface
- Functional approach: parse, don't validate
- Works with plain JavaScript too! You don't need to use TypeScript.
Sponsorship at any level is appreciated and encouraged. For individual developers, consider the Cup of Coffee tier. If you built a paid product using Zod, consider one of the podium tiers.
Speakeasy speakeasyapi.dev SDKs, Terraform, Docs. |
Deletype deletype.com |
Trigger.dev trigger.dev Effortless automation for developers |
Transloadit transloadit.com Simple file processing for developers |
Infisical infisical.com Open-source platform for secret |
Whop whop.com A marketplace for really cool internet products |
CryptoJobsList cryptojobslist.com The biggest list of crypto, blockchain and Web3 jobs |
Plain. plain.com How developers support their users |
Inngest inngest.com Serverless queues + durable workflows for TypeScript |
Storyblok storyblok.com The only headless CMS with a visual editor |
Mux mux.com The internet's video infrastructure |
Numeric numeric.io |
Marcato Partners marcatopartners.com |
|
Interval interval.com |
Seasoned Software seasoned.cc |
Bamboo Creative bamboocreative.nz |
Brandon Bayer @flybayer, creator of Blitz.js |
Jiří Brabec @brabeji |
Alex Johansson @alexdotjs |
Fungible Systems fungible.systems |
Adaptable adaptable.io |
Avana Wallet avanawallet.com Solana non-custodial wallet |
Jason Lengstorf learnwithjason.dev |
Global Illumination, Inc. ill.inc |
MasterBorn masterborn.com |
Ryan Palmer @kronodeus |
Michael Sweeney @overthemike |
Nextbase usenextbase.com |
Remotion remotion.dev |
Connor Sinnott @ConnorSinnott |
Mohammad-Ali A'râbi aerabi.com |
Supatool supatool.io |
There are a growing number of tools that are built atop or support Zod natively! If you've built a tool or library on top of Zod, tell me about it on Twitter or start a Discussion. I'll add it below and tweet it out.
- Total TypeScript Zod Tutorial by @mattpocockuk
- Fixing TypeScript's Blindspot: Runtime Typechecking by @jherr
tRPC
: Build end-to-end typesafe APIs without GraphQL.@anatine/zod-nestjs
: Helper methods for using Zod in a NestJS project.zod-endpoints
: Contract-first strictly typed endpoints with Zod. OpenAPI compatible.zhttp
: An OpenAPI compatible, strictly typed http library with Zod input and response validation.domain-functions
: Decouple your business logic from your framework using composable functions. With first-class type inference from end to end powered by Zod schemas.@zodios/core
: A typescript API client with runtime and compile time validation backed by axios and zod.express-zod-api
: Build Express-based APIs with I/O schema validation and custom middlewares.tapiduck
: End-to-end typesafe JSON APIs with Zod and Express; a bit like tRPC, but simpler.koa-zod-router
: Create typesafe routes in Koa with I/O validation using Zod.
react-hook-form
: A first-party Zod resolver for React Hook Form.zod-validation-error
: Generate user-friendly error messages fromZodError
s.zod-formik-adapter
: A community-maintained Formik adapter for Zod.react-zorm
: Standalone<form>
generation and validation for React using Zod.zodix
: Zod utilities for FormData and URLSearchParams in Remix loaders and actions.conform
: A typesafe form validation library for progressive enhancement of HTML forms. Works with Remix and Next.js.remix-params-helper
: Simplify integration of Zod with standard URLSearchParams and FormData for Remix apps.formik-validator-zod
: Formik-compliant validator library that simplifies using Zod with Formik.zod-i18n-map
: Useful for translating Zod error messages.@modular-forms/solid
: Modular form library for SolidJS that supports Zod for validation.houseform
: A React form library that uses Zod for validation.sveltekit-superforms
: Supercharged form library for SvelteKit with Zod validation.mobx-zod-form
: Data-first form builder based on MobX & Zod.@vee-validate/zod
: Form library for Vue.js with Zod schema validation.
zod-to-ts
: Generate TypeScript definitions from Zod schemas.zod-to-json-schema
: Convert your Zod schemas into JSON Schemas.@anatine/zod-openapi
: Converts a Zod schema to an OpenAPI v3.xSchemaObject
.zod-fast-check
: Generatefast-check
arbitraries from Zod schemas.zod-dto
: Generate Nest.js DTOs from a Zod schema.fastify-type-provider-zod
: Create Fastify type providers from Zod schemas.zod-to-openapi
: Generate full OpenAPI (Swagger) docs from Zod, including schemas, endpoints & parameters.nestjs-graphql-zod
: Generates NestJS GraphQL model classes from Zod schemas. Provides GraphQL method decorators working with Zod schemas.zod-openapi
: Create full OpenAPI v3.x documentation from Zod schemas.fastify-zod-openapi
: Fastify type provider, validation, serialization and @fastify/swagger support for Zod schemas.