JSON Schema Array of Objects: items, required, and examples
Last updated:
To validate an array of objects in JSON Schema, set "type": "array" at the top level and place each element's rules inside the items keyword. The items schema is a full object schema — it accepts properties, required, additionalProperties, and nested $ref pointers. Draft 2020-12 (the current standard) also adds prefixItems for tuple validation where the first N elements have distinct schemas. Use minItems and maxItems to enforce array length — for example, "minItems": 1 rejects empty arrays. This guide covers the items / prefixItems distinction, the required array inside each item schema, minItems / maxItems bounds, and uniqueItems for deduplication constraints.
Testing a schema against real data? Paste both into Jsonic's JSON Schema Validator and see item-level errors instantly.
Validate JSON SchemaBasic array of objects schema
This schema validates an array where every item is an object with an id, name, and optional email.
{
"type": "array",
"items": {
"type": "object",
"properties": {
"id": { "type": "integer" },
"name": { "type": "string" },
"email": { "type": "string", "format": "email" }
},
"required": ["id", "name"]
}
}Valid data:
[
{ "id": 1, "name": "Alice", "email": "alice@example.com" },
{ "id": 2, "name": "Bob" }
]Required fields inside array items
The required keyword applies to the object schema that contains it. For an array of objects, put required inside items, not next to the array's top-level type.
{
"type": "array",
"items": {
"type": "object",
"properties": {
"sku": { "type": "string" },
"quantity": { "type": "integer", "minimum": 1 }
},
"required": ["sku", "quantity"]
}
}For more required-field examples, see the JSON Schema examples guide.
minItems, maxItems, and uniqueItems
Array-level constraints belong beside items. Use them to control how many objects the array may contain.
{
"type": "array",
"minItems": 1,
"maxItems": 100,
"uniqueItems": true,
"items": {
"type": "object",
"properties": {
"id": { "type": "integer" }
},
"required": ["id"]
}
}uniqueItems compares whole array items. It does not mean "unique by id"; two objects with different names but the same id are still different objects unless every property matches.
Reject extra fields with additionalProperties
Set additionalProperties: false inside the item object schema to reject unknown fields on every object in the array.
{
"type": "array",
"items": {
"type": "object",
"properties": {
"id": { "type": "integer" },
"name": { "type": "string" }
},
"required": ["id", "name"],
"additionalProperties": false
}
}Without this setting, JSON Schema allows extra properties by default. That is useful for flexible API clients, but strict config files usually set it to false.
Nested arrays inside objects
An object inside the array can contain its own arrays. Define those nested arrays under the item's properties.
{
"type": "array",
"items": {
"type": "object",
"properties": {
"orderId": { "type": "string" },
"lines": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"properties": {
"sku": { "type": "string" },
"qty": { "type": "integer", "minimum": 1 }
},
"required": ["sku", "qty"]
}
}
},
"required": ["orderId", "lines"]
}
}Tuple validation
A normal items object means every array element follows the same schema. Tuple validation is different: each array position has its own schema.
{
"type": "array",
"items": [
{ "type": "string" },
{ "type": "integer" },
{ "type": "boolean" }
],
"additionalItems": false
}Use tuple validation for fixed-position records like ["Alice", 42, true]. Use items for lists where every object has the same shape.
Common errors
| Error | Fix |
|---|---|
required placed beside items | Move it inside the item object schema |
Using properties directly on an array | Put properties inside items |
Expecting uniqueItems to mean unique IDs | Enforce ID uniqueness in application logic |
| Extra item fields are accepted | Add additionalProperties: false inside items |
The JSON Schema examples guide has more copy-paste snippets for objects, enums, strings, numbers, and composition.
Frequently asked questions
How do I define an array of objects in JSON Schema?
Use type: "array" and put an object schema inside items. The object schema contains properties, required, and any object constraints such as additionalProperties.
Where do required fields go?
Put required inside the items object schema. If you put it on the top-level array schema, it will not require fields on each object.
Can JSON Schema validate every item in an array?
Yes. When items is a schema object, JSON Schema applies that schema to every element in the array.
How do I validate that an array is not empty in JSON Schema?
Use minItems: 1 on the array schema to require at least one element: {"type": "array", "minItems": 1, "items": {...}}. To cap the array size, add maxItems: 100. uniqueItems: true rejects duplicate array elements by comparing whole objects, not individual fields.
What is the difference between items and prefixItems in JSON Schema?
In Draft 4–7, items as an object applies a schema to all elements; items as an array (tuple mode) applies different schemas to each position. In Draft 2020-12, prefixItems replaced tuple-mode items, and items now controls whether additional elements beyond prefixItems are allowed. Check your validator's draft setting when using tuple validation.
Can I mix required and optional fields in JSON Schema array items?
Yes. List only mandatory fields in the required array inside items. Fields defined in properties but not in required are optional by default. Adding additionalProperties: false ensures only listed fields are accepted, whether or not they are required.
Validate your array schema
Paste your schema and sample JSON into Jsonic's JSON Schema Validator to check item paths, required fields, and nested array rules.
Open Schema ValidatorRecommended reading
- Designing Data-Intensive Applications (2nd Edition) — Martin Kleppmann & Chris RiccominiThe modern classic on data systems — encoding formats, schemas, replication, and stream processing.
- JavaScript: The Definitive Guide (7th Edition) — David FlanaganThe complete reference for the language JSON came from — serialization, async, and the full standard library.
As an Amazon Associate, Jsonic earns from qualifying purchases.