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.object
required
Object containing additional properties to add or override.
safeExtend()
Safely extend an object schema, allowing property overrides even with refinements.merge()
Merge two object schemas together.pick()
Create a new schema with only the specified properties.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.object
required
Object with keys to omit. Set values to
true to exclude, false to include.partial()
Make all properties optional.object
Optional object specifying which keys to make optional.
required()
Make all properties required (remove optionality).object
Optional object specifying which keys to make required.
keyof()
Extract the keys of an object schema as an enum.catchall()
Define a schema to validate all unrecognized keys.ZodType
required
Schema to validate unrecognized keys against.
passthrough()
Allow unrecognized keys to pass through without validation.loose()
Allow unrecognized keys without validation (replaces.passthrough()).
strict()
Disallow unrecognized keys (fail validation).strip()
Remove unrecognized keys (default behavior).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
Related
- z.record() - For dynamic key-value objects
- z.intersection() - For combining schemas
- z.union() - For alternative schemas