JSON Schema for an Array of Objects From an Empty Sample
An empty array establishes the container type but gives a generator no example item. Use items to describe a representative object, and decide separately whether an empty list should be allowed.
Worked example
An array of event records that may be empty
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "array",
"items": {
"type": "object",
"properties": {"eventId": {"type": "string"}},
"required": ["eventId"]
}
}Steps
- Choose the contract for one future row. The example requires a string eventId in every row, including the second and later rows.
- Put that object schema under items. Add minItems separately only if the caller must send at least one event.
- Check three cases: [] should pass; [{"eventId":"E-27"}] should pass; [{"eventId":"E-27"}, {"eventId":27}] should fail at the second row.
What to check
- The linked validator should point to /1/eventId for the bad second row. The first row has index 0.
- This contract covers the shape of each row. It does not require event IDs to be unique across rows; check that separately if the application needs it.