Object schema construction
Define an object schema from a reusable map of field validators.
Zod · Type Alias
ZodRawShape is the object-like map of property names to Zod schemas used to define Zod object fields. Use it directly as a reusable shape or pass it to z.object to create an object schema.
ZodRawShape is the structural type for the schema map supplied to an object schema. Each key names a property, and each value describes that property's validation rules; the map can be inspected through an object's .shape property and passed to z.object to construct the complete schema.
type ZodRawShape = Record<string, ZodTypeAny>import { z } from "zod";
const shape = {
name: z.string(),
age: z.number().int(),
} satisfies z.ZodRawShape;
const Person = z.object(shape);
const person = Person.parse({ name: "Ada", age: 36 });A raw shape is a plain object whose property values are Zod schemas; passing it to z.object creates an object schema.
Define an object schema from a reusable map of field validators.
Retrieve or reuse individual field validators from an existing object schema.
Keep field definitions separate so related object schemas can share or extend them.
ZodRawShape is the shape of a Zod object: a mapping from property keys to Zod schemas. It is useful when defining or reusing the field-schema map before constructing an object schema with z.object.
Follow-up: How can you inspect an existing object's raw shape? Use its .shape property, which exposes the schemas for its individual keys.
A raw shape contains validators for fields such as strings and numbers. z.object(shape) turns that mapping into a Zod object schema that can validate complete objects.
Follow-up: What does the resulting object schema provide? It can be used with Zod's parsing APIs to validate input and produce typed output.
The individual schemas are available through an object's .shape property. For example, accessing a name entry yields the schema associated with that key, rather than the parsed value.
Follow-up: Why is this useful? It lets code inspect or reuse field validators when composing related object schemas.
z.objectZodObject.shapez.stringz.number