Array Items Schema — Validating Array Elements

Generate JSON Schema for arrays with typed elements using the items keyword. Learn how homogeneous array validation works and how to add length constraints.

Array Schemas

Detailed Explanation

Generating Schemas for Arrays

When the generator encounters a JSON array, it inspects the elements and produces an "items" schema describing the shape each element must follow.

Homogeneous Arrays

The most common case is an array where every element has the same type:

["apple", "banana", "cherry"]

Generated schema:

{
  "type": "array",
  "items": { "type": "string" }
}

For arrays of objects:

[
  { "id": 1, "name": "Alice" },
  { "id": 2, "name": "Bob" }
]

Generated schema:

{
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "id": { "type": "integer" },
      "name": { "type": "string" }
    },
    "required": ["id", "name"]
  }
}

The generator merges the properties from all elements to build a unified items schema.

Length Constraints

After generation, add length constraints to control array size:

{
  "type": "array",
  "items": { "type": "string" },
  "minItems": 1,
  "maxItems": 100,
  "uniqueItems": true
}
  • minItems — the array must contain at least this many elements.
  • maxItems — the array must not exceed this many elements.
  • uniqueItems — when true, duplicate elements are rejected.

Mixed-Type Arrays

If the generator encounters elements of different types (e.g., [1, "two", true]), it may produce a union type in items:

{
  "type": "array",
  "items": {
    "oneOf": [
      { "type": "integer" },
      { "type": "string" },
      { "type": "boolean" }
    ]
  }
}

Mixed-type arrays are less common in well-designed APIs but appear in configuration formats and legacy systems.

The contains Keyword

Use contains when you only need to assert that at least one element matches a schema, without constraining every element. This is useful for validation like "the array must include at least one admin user."

Use Case

Generate array schemas for lists of tags, user collections, order line items, log entries, or any API endpoint that returns or accepts arrays of structured data.

Try It — JSON Schema Generator

Open full tool