What if your schema validation library was 100x faster, tree-shakeable, and still had the same API you already know?
Zod 4 is the next major version of the most popular TypeScript-first schema validation library — rebuilt from scratch for performance.
What Changed in Zod 4
Zod 3 was the gold standard for TypeScript validation, but it had performance issues at scale. Zod 4 fixes everything:
- 100x faster parsing in benchmarks
- Tree-shakeable — only pay for what you use (7kb min for basic schemas)
- JSON Schema output — native toJSONSchema method
- Recursive types — no more z.lazy workarounds
- Better error messages — structured error formatting built-in
Quick Start
npm install zod@next
import { z } from "zod";
const UserSchema = z.object({
name: z.string().min(1),
email: z.email(),
age: z.number().min(18).max(120),
role: z.enum(["admin", "user", "moderator"]),
});
type User = z.infer<typeof UserSchema>;
const user = UserSchema.parse(requestBody);
const result = UserSchema.safeParse(requestBody);
New in Zod 4: JSON Schema
const schema = z.object({
title: z.string(),
price: z.number().positive(),
tags: z.array(z.string()),
});
const jsonSchema = z.toJSONSchema(schema);
Real Use Case
An API gateway validated 50K requests/second with Zod 3. CPU usage spiked to 80% just on validation. After upgrading to Zod 4, the same traffic used 12% CPU. They saved two server instances — about $400/month.
When to Use Zod 4
- API input validation
- Form validation (React Hook Form, Formik integration)
- Config file parsing
- OpenAPI schema generation
- Any TypeScript project that touches external data
Get Started
Visit zod.dev — drop-in upgrade from Zod 3, full migration guide included.
Need custom data pipelines or scraping solutions? Check out my Apify actors or email me at spinov001@gmail.com for custom solutions.
Top comments (0)