additionalItems : Schema

additionalItems

Schema

If items is set to an array of schemas, validation succeeds if each element of the instance not covered by it validates against this schema.

Value This keyword must be set to a valid JSON Schema Hint: Use the jsonschema metaschema and jsonschema lint commands to catch keywords set to invalid values
Kind Applicator Annotation
Applies To Array
Base Dialect 2019-09
Changed In None
Introduced In Draft 3
Vocabulary Applicator
Specification https://json-schema.org/draft/2019-09/draft-handrews-json-schema-02#rfc.section.9.3.1.2
Metaschema https://json-schema.org/draft/2019-09/meta/applicator
Official Tests draft2019-09/additionalItems.json
Default {}
Annotation Boolean A boolean true if it applied to any item of the instance Hint: Use the jsonschema validate command to collect annotations from the command-line
Affected By
Affects
Also See

The additionalItems keyword restricts array instance items not described by the sibling items keyword (when items is in array form), to validate against the given subschema. Whether this keyword was evaluated against any item of the array instance is reported using annotations.

Remember that JSON Schema is a constraint-driven language. Therefore, non-array instances successfully validate against this keyword. If needed, make use of the type keyword to constraint the accepted type accordingly.

Examples

A schema that constrains array instances to start with a boolean item followed by a number item, with only string items allowed beyond that Schema
{
  "$schema": "https://json-schema.org/draft/2019-09/schema",
  "items": [ { "type": "boolean" }, { "type": "number" } ],
  "additionalItems": { "type": "string" }
}
Valid An array value that consists of a boolean item followed by a number item is valid Instance
[ false, 35 ]
Annotations
{ "keyword": "/items", "instance": "", "value": true }
Valid An array value that consists of a boolean item followed by a number item and string items is valid Instance
[ false, 35, "foo", "bar" ]
Annotations
{ "keyword": "/items", "instance": "", "value": 1 }
{ "keyword": "/additionalItems", "instance": "", "value": true }
Invalid An array value that consists of a boolean item followed by a number item and non-string items is invalid Instance
[ false, 35, { "foo": "bar" } ]
Valid An empty array value is valid Instance
[]
Valid A non-array value is valid Instance
"Hello World"
A schema that prevents additional items beyond the tuple Schema
{
  "$schema": "https://json-schema.org/draft/2019-09/schema",
  "items": [ { "type": "boolean" }, { "type": "number" } ],
  "additionalItems": false
}
Valid An array value with exactly two items matching the tuple is valid Instance
[ false, 35 ]
Annotations
{ "keyword": "/items", "instance": "", "value": true }
Invalid An array value with items beyond the tuple is invalid Instance
[ false, 35, "foo" ]
A schema that describes open items and additional items leads to the additional items schema being ignored Schema
{
  "$schema": "https://json-schema.org/draft/2019-09/schema",
  "items": { "type": "number" },
  "additionalItems": { "type": "string" }
}
Valid An array value with only numbers is valid Instance
[ 1, 2, 3 ]
Annotations
{ "keyword": "/items", "instance": "", "value": true }
Valid An array value with numbers and strings is valid as the keyword is ignored Instance
[ 1, 2, "foo" ]
Annotations
{ "keyword": "/items", "instance": "", "value": true }
A schema with only additional items definitions leads to the additional items schema being ignored Schema
{
  "$schema": "https://json-schema.org/draft/2019-09/schema",
  "additionalItems": { "type": "string" }
}
Valid Any array is valid Instance
[ 1, 2, 3 ]
Valid A non-array value is valid Instance
"Hello World"