Zod logo
zod logo

Zod

TypeScript-first schema validation with static type inference

Zod CI statusCreated by Colin McDonnellLicensenpmstars
Website  •  Discord  •  𝕏  •  Bluesky

Zod 4 is now in beta! Click here to read the release notes.




Featured sponsor: Fern
fern logo

Interested in featuring? Get in touch.

Introduction

Zod is a TypeScript-first validation library. Using Zod, you can define schemas you can use to validate data, from a simple string to a complex nested object.

import * as z from "zod";
 
const User = z.interface({
  name: z.string(),
});
 
// some untrusted data...
const input = { /* stuff */ };
 
// the parsed result is validated and type safe!
const data = User.parse(input);
 
// so you can use it with confidence :)
console.log(data.name);

Features

  • Zero external dependencies
  • Works in Node.js and all modern browsers
  • Tiny: 2kb core bundle (gzipped)
  • Immutable API: methods return a new instance
  • Concise interface
  • Works with TypeScript and plain JS
  • Built-in JSON Schema conversion
  • Extensive ecosystem

Requirements

Zod is tested against TypeScript v5.5 and later. Older versions may work but are not officially supported.

You must enable strict mode in your tsconfig.json. This is a best practice for all TypeScript projects.

// tsconfig.json
{
  // ...
  "compilerOptions": {
    // ...
    "strict": true
  }
}

Installation

npm install zod       # npm
deno add npm:zod      # deno
yarn add zod          # yarn
bun add zod           # bun
pnpm add zod          # pnpm

Zod also publishes a canary version on every commit. To install the canary:

npm install zod@canary       # npm
deno add npm:zod@canary      # deno
yarn add zod@canary          # yarn
bun add zod@canary           # bun
pnpm add zod@canary          # pnpm

Sponsors

Sponsorship at any level is appreciated and encouraged. If you built a paid product using Zod, consider one of the corporate tiers.


Platinum

CodeRabbit logo

Cut code review time & bugs in half

coderabbit.ai


Gold

Courier logo (light theme)

The API platform for sending notifications

courier.com
Liblab logo (light theme)

Generate better SDKs for your APIs

liblab.com
Neon logo (light theme)

Serverless Postgres — Ship faster

neon.tech
Retool logo (light theme)

Build AI apps and workflows with Retool AI

retool.com
Stainless logo (light theme)

Generate best-in-class SDKs

stainlessapi.com
Speakeasy logo (light theme)

SDKs & Terraform providers for your API

speakeasy.com

Silver


Bronze

On this page