maximum : Number

maximum

Number

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

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

The maximum keyword is used to set the upper limit on numeric instances. It specifies that the numeric value being validated must be less than or equal to the provided maximum value.

  • Applies only to number data types (integers and floats).
  • Validation succeeds if the number is less than or equal to the specified maximum.

Examples

Schema defining the upper limit of 10 on numeric values Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "number",
  "maximum": 10
}
Valid An instance with a numeric value less than 10 is valid Instance
9.5
Invalid An instance with a numeric value greater than 10 is invalid Instance
15
Valid An instance with a numeric value equal to 10 is valid Instance
10
Schema allowing either a boolean value or a numeric value with an upper limit of 20.99 Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": [ "boolean", "number" ],
  "maximum": 20.99
}
Valid An instance with a numeric value less than 20.99 is valid Instance
15
Invalid An instance with a string datatype is invalid Instance
"Hello World!"
Valid An instance with a boolean value is valid Instance
true