Skip to main content

Basic Usage

Create an object schema by defining the shape of its properties.

Signature

object
An object where each key maps to a Zod schema. Defines the structure of the object.
string | ZodObjectParams
Optional error message (string) or configuration object.

Properties

object
Access the object’s shape definition.

Methods

extend()

Add new properties to an object schema or override existing ones.
When extending an object with refinements, you can only add new properties. Use .safeExtend() to override existing properties.
Signature:
object
required
Object containing additional properties to add or override.

safeExtend()

Safely extend an object schema, allowing property overrides even with refinements.
Signature:

merge()

Deprecated. Use A.extend(B.shape) instead.
Merge two object schemas together.
Signature:

pick()

Create a new schema with only the specified properties.
Cannot be used on object schemas containing refinements. The refinements would apply to the full object, not the picked subset.
Signature:
object
required
Object with keys to pick. Set values to true to include, false to exclude.

omit()

Create a new schema excluding the specified properties.
Cannot be used on object schemas containing refinements.
Signature:
object
required
Object with keys to omit. Set values to true to exclude, false to include.

partial()

Make all properties optional.
You can also make specific properties optional:
Signature:
object
Optional object specifying which keys to make optional.

required()

Make all properties required (remove optionality).
You can also make specific properties required:
Signature:
object
Optional object specifying which keys to make required.

keyof()

Extract the keys of an object schema as an enum.
Signature:

catchall()

Define a schema to validate all unrecognized keys.
Signature:
ZodType
required
Schema to validate unrecognized keys against.

passthrough()

Deprecated. Use .loose() or z.looseObject() instead.
Allow unrecognized keys to pass through without validation.

loose()

Allow unrecognized keys without validation (replaces .passthrough()).
Signature:

strict()

Disallow unrecognized keys (fail validation).
Signature:

strip()

Remove unrecognized keys (default behavior).
Signature:

Object Variants

z.strictObject()

Create a strict object schema that rejects unrecognized keys.

z.looseObject()

Create a loose object schema that allows unrecognized keys.

Type Inference