items keyword applies a schema to elements of an array instance. It can validate all array elements or only those not covered by prefixItems.
Syntax
Behavior
Theitems keyword validates array elements with these rules:
- If
prefixItemsis present in the same schema object,itemsapplies its schema to elements after those validated byprefixItems - If
prefixItemsis absent,itemsapplies its schema to all elements - If
prefixItemsvalidates more elements than exist in the array,itemsvalidates nothing - Produces a boolean
trueannotation when applied to any elements - Affects the behavior of
unevaluatedItems
Examples
Uniform Array
Validate all elements with the same schema:["a", "b", "c"], []Invalid:
[1, 2, 3], ["a", 1, "b"]
Array of Objects
Validate array of structured objects:With prefixItems
Combine withprefixItems for mixed arrays:
- Index 0: must be a string
- Index 1: must be an integer
- Index 2+: must be booleans
["hello", 42], ["hello", 42, true, false]Invalid:
["hello", 42, "extra"]
Nested Arrays
Validate arrays of arrays:Array with Length Constraints
Combine with array length keywords:["a"], ["hello", "world"]Invalid:
[] (too few items), ["a", "b", "c", "d", "e", "f"] (too many items), [""] (empty string)
Tagged Union Array
Array of polymorphic objects:No Additional Items After Prefix
Prohibit items beyond those inprefixItems:
["hello", 42]Invalid:
["hello", 42, "extra"]
Strict Tuple
Define a fixed-length tuple with no additional items:[1.0, 2.0, 3.0]Invalid:
[1, 2], [1, 2, 3, 4]
Interaction with prefixItems
TheprefixItems keyword validates a specific number of leading array elements. The items keyword then validates remaining elements:
- Array
[1, 2]: First two validated byprefixItems, no items foritems→ valid - Array
[1, 2, "a", "b"]: First two byprefixItems, rest byitems→ valid - Array
[1, 2, 3]: Third element failsitems(not a string) → invalid
Annotations
Whenitems applies its schema to any array elements, it produces an annotation with boolean value true. This annotation indicates that all remaining array elements have been evaluated.
This annotation affects unevaluatedItems behavior.
Default Behavior
Omitting theitems keyword has the same assertion behavior as an empty schema - all items are valid, but no annotation is produced.
Common Use Cases
- Homogeneous arrays: Arrays where all elements have the same type/structure
- Lists: Collections of similar items (users, products, events)
- Variable-length tuples: Fixed prefix with variable tail
- Nested data: Arrays of objects or arrays of arrays
- API responses: Validate array-based response payloads
Notes
- Prior to draft 2020-12,
itemscould be either a schema or an array of schemas - The array form is now handled by
prefixItems - Always use
type: "array"when usingitems - Combine with
minItems/maxItemsfor length constraints - Use
uniqueItems: trueto require distinct elements - The
containskeyword provides different semantics (at least N items matching)
Best Practices
- Be explicit about whether arrays should be homogeneous or have a tuple structure
- Use
prefixItems+items: falsefor strict tuples - Use
itemsalone for homogeneous arrays - Combine
prefixItems+itemsfor “at least N specific items, then more of type X” - Consider
containswhen you need “at least one item matching” semantics