Purpose: This page documents Zod's collection schema types for validating homogeneous and heterogeneous data structures. Collection schemas include arrays, tuples, sets, maps, and records, each supporting element-specific validation and size constraints.
For object schemas with named properties, see Object Schemas. For union types representing alternative schemas, see Union and Discriminated Unions.
Array schemas validate ordered collections where all elements conform to a single element schema.
Arrays support minimum, maximum, exact length, and nonempty constraints:
The $ZodArray type is defined in the core schema system. Validation process:
Array.isArray().[0], [1]) packages/zod/src/v4/classic/tests/index.test.ts218-220Sources: packages/docs/content/api.mdx1152-1200 packages/zod/src/v4/classic/tests/index.test.ts217-221
Tuple schemas validate fixed-length arrays where each position has a specific schema.
Tuples support rest elements for additional items and trailing optional elements:
The $ZodTuple type handles positional validation:
.rest() is defined, validates all remaining elements against the rest schema packages/zod/src/v4/classic/tests/tuple.test.ts109-112 .Sources: packages/zod/src/v4/classic/tests/tuple.test.ts1-205 packages/docs/content/api.mdx1202-1250
Set schemas validate unordered collections of unique values.
Sets support the same size constraints as arrays:
The $ZodSet type validation:
instanceof Set.Sources: packages/docs/content/api.mdx1252-1288 packages/docs/content/json-schema.mdx70
Map schemas validate collections of key-value pairs with independent schemas for keys and values.
The $ZodMap type validation:
instanceof Map.[i, "key"] and values with path [i, "value"].Sources: packages/docs/content/api.mdx1290-1310 packages/docs/content/json-schema.mdx69
Record schemas validate objects with dynamic keys where all keys and values conform to specific schemas.
The key schema can be an enum or literal for exhaustive validation:
The $ZodRecord type features:
Symbol keys packages/zod/src/v4/core/tests/record-constructor.test.ts101-106Object.keys() and Object.getOwnPropertySymbols(), skipping non-enumerable properties packages/zod/src/v4/core/tests/record-constructor.test.ts69-86z.enum), Zod ensures all required keys are present in the input packages/zod/src/v4/classic/tests/record.test.ts35-77constructor field in objects packages/zod/src/v4/core/tests/record-constructor.test.ts4-36Sources: packages/zod/src/v4/classic/tests/record.test.ts1-186 packages/zod/src/v4/core/tests/record-constructor.test.ts1-125 packages/docs/content/api.mdx1312-1360
Sources: packages/docs/content/api.mdx1152-1360 packages/zod/src/v4/classic/tests/tuple.test.ts26-39
All collection schemas follow a common validation pattern with variations for their specific data structures.
Sources: packages/zod/src/v4/classic/tests/tuple.test.ts4-53 packages/zod/src/v4/classic/tests/record.test.ts47-77
Zod supports native JSON Schema conversion via z.toJSONSchema().
| Zod Type | JSON Schema Mapping | Supported |
|---|---|---|
z.array() | type: "array" | ✅ |
z.tuple() | type: "array", prefixItems | ✅ |
z.record() | type: "object", additionalProperties | ✅ |
z.set() | N/A | ❌ |
z.map() | N/A | ❌ |
Unrepresentable types like z.set() and z.map() will throw an error by default during conversion unless the unrepresentable parameter is set to "any" packages/docs/content/json-schema.mdx60-74 packages/docs/content/json-schema.mdx210-235
Sources: packages/docs/content/json-schema.mdx1-129 packages/zod/src/v4/core/tests/record-constructor.test.ts120-125
Each collection type uses specific path formats for reporting issues.
| Collection | Path Format | Example Path |
|---|---|---|
| Array | [index] | [0], [1] |
| Tuple | [index] | [0], [1] packages/zod/src/v4/classic/tests/tuple.test.ts18-20 |
| Set | [iterationIndex] | [0], [1] |
| Map Key | [iterationIndex, "key"] | [0, "key"] |
| Map Value | [iterationIndex, "value"] | [0, "value"] |
| Record | [keyName] | ["Salmon"] packages/zod/src/v4/classic/tests/record.test.ts68-70 |
Sources: packages/zod/src/v4/classic/tests/tuple.test.ts11-24 packages/zod/src/v4/classic/tests/record.test.ts62-76
Refresh this wiki
This wiki was recently refreshed. Please wait 2 days to refresh again.