Transforming and Refining Zod Data
Go beyond basic validation by transforming parsed values and adding custom refinement rules with Zod.
Beyond Pass/Fail
Zod does more than accept or reject data. It can transform valid input into a cleaner shape and apply custom rules that built-in validators cannot express.
The transform Method
.transform() changes a value after it passes validation, producing a new output type.
const trimmed = z.string().transform((s) => s.trim());
trimmed.parse(" hi "); // "hi"All lessons in this course
- Introduction to Zod Schemas
- Defining Complex Zod Schemas
- Integrating Zod in tRPC Procedures
- Transforming and Refining Zod Data