After a year of active development, Zod 4 is officially released with major improvements. This stable version is faster, slimmer, and more TypeScript-optimized compared to the previous Zod 3.
Highlights of Zod 4
🚀 Outstanding Performance
- 14x faster string parsing: Deep optimizations in string validation make your app respond much faster, especially when handling large amounts of text data.
- 7x faster array parsing: Efficiently process complex or large arrays, minimizing latency in data validation.
- 6.5x faster object parsing: Ideal for objects with many fields, ensuring smoother validation and faster API responses.
⚡ TypeScript Compiler Optimization
- Reduces type instantiations by up to 100x, speeding up the TypeScript compiler significantly, especially for large and complex codebases.
- Compilation time is improved by around 10x compared to Zod 3, providing a smoother developer experience and faster editor feedback.
📦 Reduced Bundle Size
- Core bundle size is 2.3x smaller than Zod 3, making your applications lighter and faster to load.
- The
zod/v4-mini
variant is even lighter (~1.88KB gzip), using a functional API optimized for tree-shaking, perfect for projects with strict bundle size limits.
🏷️ Powerful Metadata System
- Allows attaching strongly-typed metadata to schemas, enabling easy mapping to standard JSON Schema.
- Great for automation tools, API documentation, and data transformation workflows.
🔄 Simple Recursive and Mutually Recursive Types
- Define self-referencing or mutually referencing types (e.g., category trees, user-post relationships) directly without complex casting hacks.
- Increases code clarity and maintainability.
🌐 Internationalized Error API
- Supports a locales system to translate error messages into multiple languages, improving user experience in global applications.
- English locale available now, with community contributions expected for more languages.
✨ New Top-Level String Format APIs
- Popular formats like
email()
,uuid()
,ip()
, andurl()
are now top-level functions, leading to cleaner code and better tree-shaking. - Older method-based APIs on strings remain available but are deprecated.
🔤 z.stringbool()
- Converts strings to booleans using a flexible, environment-variable style (e.g.,
"true"
,"yes"
,"1"
→true
;"false"
,"no"
,"0"
→false
). - Customizable truthy/falsy values to fit your specific needs, making it easy to validate boolean-like string inputs.
🎯 Simplified Error Customization API
- Unifies various error customization approaches into a single
error
parameter, which can be a string or function, enabling concise and clear error definitions. - Reduces complexity and confusion when writing validations and handling errors.
🔀 More Powerful Discriminated Unions
- Supports multiple schema types as discriminators, including unions, pipes, and nested objects.
- Allows creating complex and maintainable type classifications for diverse data structures.
🔧 .overwrite()
Method
- Alternative to
.transform()
for applying data transformations without changing the inferred type, preserving type information. - Useful for simple data manipulation without breaking compatibility with JSON Schema or inferred types.
🧩 Zod Mini
- A super lightweight functional API variant that removes excess methods to optimize tree-shaking, resulting in very small final bundles.
- Perfect for front-end apps needing minimal download sizes while still using Zod for validation.
🚀 Conclusion
Zod 4 marks a significant advancement in TypeScript schema validation, offering enhanced performance, reduced bundle sizes, and a more intuitive API. With features like improved TypeScript compiler efficiency, a powerful metadata system, and streamlined error handling, Zod 4 is designed to meet the needs of modern development.
For comprehensive documentation, including guides on defining schemas, customizing errors, and integrating with JSON Schema, visit the official Zod 4 documentation: https://zod.dev/v4.
Happy coding! 😊