maxLength : Integer
maxLength
IntegerA 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 |
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 is used to specify the maximum length of a string instance. It is used to enforce a constraint on the maximum number of characters allowed for a string instance.
- String length is counted in characters, not bytes.
- Validation succeeds if the string length is less than or equal to the specified
maxLength
.
Examples
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "string",
"maxLength": 10
}
"foo"
"This is an invalid string"
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": [ "string", "number" ],
"maxLength": 20
}
"This is valid"
"This description is too long"
55
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "string",
"maxLength": 3
}
"\u0066\u006F\u006F" // --> "foo"
"\u0048\u0065\u006C\u006C\u006F" // --> "Hello"