maxContains : Integer



The number of times that the contains keyword (if set) successfully validates against the instance must be less than or equal to the given integer.

Kind Assertion
Applies To Array
Dialect 2020-12
Introduced In 2019-09
Vocabulary Validation
Affected By
Also see

The maxContains keyword is used in conjunction with the contains keyword to specify the maximum number of items in an array instance that must validate against the contains subschema.

  • This keyword applies only to arrays.
  • The value of this keyword must be a non-negative integer.
  • If contains is not present within the same schema object, then this keyword has no effect.


Schema with the 'maxContains' and 'contains' keyword Schema
  "$schema": "",
  "type": "array",
  "contains": { "type": "string" },
  "maxContains": 2
An array instance with 2 or less items successfully validating against the 'contains' subschema is valid Instance
[ "Car", "Bus", 1, 2 ]
An array instance with more than 2 items successfully validating against the 'contains' subschema is invalid Instance
[ "Car", "Bus", 1, 2, "Bike" ]
Schema with the 'maxContains' keyword Schema
  "$schema": "",
  "type": "array",
  "maxContains": 2
// If contains is not present, 'maxContains' has no effect on validation.
An array instance with any items is valid Instance
[ "John", false, 29, { "foo": "bar" }, [ 5, 7 ] ]
An empty array is also valid Instance