exclusiveMaximum : Number

exclusiveMaximum

Number

Validation succeeds if the numeric instance is less than the given number.

Value This keyword must be set to a number
Kind Assertion
Applies To Number
Dialect 2020-12
Changed In Draft 6
Introduced In Draft 3
Vocabulary Validation
Specification https://json-schema.org/draft/2020-12/json-schema-validation.html#section-6.2.3
Metaschema https://json-schema.org/draft/2020-12/meta/validation
Official Tests draft2020-12/exclusiveMaximum.json
Default None
Annotation None
Affected By None
Affects None
Also See

The exclusiveMaximum keyword is used to set an exclusive upper limit on numeric instances. It specifies that the numeric value being validated must be strictly less than (not equal to) the provided maximum value.

  • Applies only to number data types (integers and real numbers).
  • Validation succeeds if the number is strictly less than the specified exclusiveMaximum.

Examples

Schema defining exclusive upper limit of 10 on numeric values Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "number",
  "exclusiveMaximum": 10
}
Invalid An instance with numeric value greater than 10 is invalid Instance
15
Valid An instance with numeric value less than 10 is valid Instance
9.5
Invalid An instance with numeric value equal to 10 is invalid Instance
10
Schema allowing either a string value or a numeric value with an exclusive upper limit of 20.99 Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": [ "string", "number" ],
  "exclusiveMaximum": 20.99
}
Valid An instance with a numeric value less than 20.99 is valid Instance
15.67
Invalid An instance with a boolean datatype is invalid Instance
true
Valid An instance with a string value is valid Instance
"Hello World!"
Invalid An instance with a numeric value greater than 20.99 is invalid Instance
29
Schema with both 'maximum' and 'exclusiveMaximum' keywords Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "number",
  "exclusiveMaximum": 10,
  "maximum": 20
}
Valid An instance with numeric value less than 10 is valid Instance
9.5
Invalid An instance with numeric value greater than or equal to 10 is invalid Instance
15
  • Note: Here, the exclusiveMaximum takes precedence, even though maximum is 20. Only numbers less than 10 are valid.