Array Items Schema — Uniform Type Validation

Use the items keyword in JSON Schema to enforce a uniform type on all array elements. Validate arrays of integers, emails, and nested coordinate arrays.

Array Constraints

JSON Schema

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "userIds": {
      "type": "array",
      "items": {
        "type": "integer",
        "minimum": 1
      },
      "minItems": 1,
      "maxItems": 100
    },
    "emails": {
      "type": "array",
      "items": {
        "type": "string",
        "format": "email"
      }
    },
    "coordinates": {
      "type": "array",
      "items": {
        "type": "array",
        "items": {
          "type": "number"
        },
        "minItems": 2,
        "maxItems": 2
      }
    }
  },
  "required": ["userIds"]
}

Test Data

{
  "userIds": [101, 202, 303, 404],
  "emails": ["alice@example.com", "bob@example.com"],
  "coordinates": [[37.7749, -122.4194], [40.7128, -74.006]]
}

Detailed Explanation

Uniform Array Item Validation

The items keyword defines a schema that every element in the array must satisfy. This is the most common way to validate arrays — ensuring all elements share the same type and constraints.

Basic Syntax

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

Every element in the array must be a non-empty string. An empty array [] also passes because there are no elements to violate the constraint.

How the Example Schema Works

The schema defines three arrays with different item types:

  1. userIds — an array of positive integers. The items schema requires each element to be an integer with minimum: 1. The array itself must contain 1 to 100 elements. The test value [101, 202, 303, 404] passes — four positive integers.

  2. emails — an array of email strings. Each element must satisfy format: "email". The test value contains two valid email addresses.

  3. coordinates — an array of coordinate pairs. Each element is itself an array of exactly two numbers (enforced by minItems: 2 and maxItems: 2). This creates a list of [latitude, longitude] pairs. The test value contains two valid coordinate pairs.

Nested Arrays

The coordinates field demonstrates nested array validation. The outer items schema is itself an array schema:

{
  "type": "array",
  "items": {
    "type": "array",
    "items": { "type": "number" },
    "minItems": 2,
    "maxItems": 2
  }
}

This pattern is useful for matrices, GeoJSON coordinates, and any two-dimensional data structure.

items vs. contains

  • items — every element must match the schema.
  • contains — at least one element must match the schema.
{
  "type": "array",
  "contains": { "type": "string", "const": "admin" }
}

This requires the array to contain at least one "admin" string, but other elements can be anything. Use contains when you need to assert the presence of a specific value without constraining all elements.

Empty Arrays

By default, an empty array [] passes items validation because there are no elements to check. Use minItems: 1 if you need at least one element. This is a common gotcha — forgetting minItems allows empty arrays to slip through.

Use Case

Use items validation for bulk operation endpoints (batch delete by IDs, multi-invite by emails), geographic data APIs accepting coordinate lists, and any API that accepts a homogeneous list. Combined with minItems and maxItems, it provides complete control over array payloads.

Try It — JSON Schema Validator

Open full tool