0Pricing
tRPC End-to-End Type Safe APIs · Lesson

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

  1. Introduction to Zod Schemas
  2. Defining Complex Zod Schemas
  3. Integrating Zod in tRPC Procedures
  4. Transforming and Refining Zod Data
← Back to tRPC End-to-End Type Safe APIs