maxLength : Integer

maxLength

Integer

A string instance is valid against this keyword if its length is less than, or equal to, the value of this keyword.

Value This keyword must be set to a zero or positive integer
Kind Assertion
Applies To String
Base 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.3.1
Metaschema https://json-schema.org/draft/2020-12/meta/validation
Official Tests draft2020-12/maxLength.json
Default None
Annotation None
Affected By None
Affects None
Also See

The maxLength keyword restricts string instances to consists of an inclusive maximum number of Unicode code-points (logical characters), which is not necessarily the same as the number of bytes in the string.

Remember that JSON Schema is a constraint-driven language. Therefore, non-string 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 string instances to contain at most 3 code points Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "maxLength": 3
}
Valid A string value that consists of 3 code-points is valid Instance
"foo"
Invalid A string value that consists of more than 3 code-points is invalid Instance
"こんにちは"
Valid A string value that consists of less than 3 code-points is valid Instance
"hi"
Valid A non-string value is valid Instance
55