Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Zod · Module

.toUpperCase

.toUpperCase() transforms parsed strings to uppercase. It takes no arguments and can be chained with other string transformations such as .trim().

How it works

.toUpperCase() is a string schema transformation that converts a successfully parsed string to uppercase. It can be chained with other string transformations such as .trim(); the resulting schema still represents a string.

Syntax

z.string().toUpperCase()

Returns

A Zod string schema that uppercases parsed string values.

Key points

  • Call .toUpperCase() on a string schema to create an uppercase-normalizing parser.
  • The method can be chained after .trim() when whitespace should be removed before uppercasing.
  • When used in the documented chain with .prefault(" tuna "), parsing undefined yields the normalized value "TUNA".
  • .toUpperCase() appears among string transformations, alongside Unicode normalization and case conversion helpers.
  • The current implementation category indicates that overwrite-based string transformations do not change the inferred type.

Common mistakes

  • In current Zod, these methods are implemented through .overwrite(), so they preserve the schema's inferred string type rather than creating a different output type.

Example: Normalize a string to uppercase

import { z } from "zod";

const schema = z.string().trim().toUpperCase();

console.log(schema.parse("  tuna ")); // "TUNA"

Trims surrounding whitespace, then converts the parsed string to uppercase.

When to use it

Normalize case

Canonicalizing user-entered identifiers or labels before storage or comparison.

Clean and uppercase input

Combining whitespace cleanup and case conversion in an input pipeline.

Preserve string typing

Applying a string transformation while retaining a string schema type.

Interview questions

QWhat does .toUpperCase() do?

It is called on a z.string() schema and uppercases the string during parsing. For example, z.string().toUpperCase().parse("hello") produces "HELLO".

Follow-up: How would you normalize both whitespace and case? Chain the transformations: z.string().trim().toUpperCase().

QWhen is the transformation applied?

It is a transformation method listed alongside .trim(), .toLowerCase(), and .normalize(). The input must first satisfy the string schema, after which the uppercase conversion is applied.

Follow-up: What happens if the input is not a string? The base z.string() schema rejects it before the string transformation can run.

QWhat is the method signature and output type?

The method takes no argument: z.string().toUpperCase(). Its parsed result remains a string, with lowercase letters converted to uppercase.

Follow-up: How can the operation be combined with a default-like preprocessing flow? Chain it with other documented schema methods, such as .trim() and .prefault().

  • z.string
  • trim
  • toLowerCase
  • normalize
  • prefault
  • overwrite

Source: Defining schemas | Zod. Checked 2026-10-15.