minLength : Integer
minLength
IntegerA string instance is valid against this keyword if its length is greater 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.2 |
Metaschema | https://json-schema.org/draft/2020-12/meta/validation |
Official Tests | draft2020-12/minLength.json |
Default |
0
|
Annotation | None |
Affected By | None |
Affects | None |
Also See |
|
The minLength
keyword restricts string instances to consists of an inclusive
minimum number of Unicode code-points (logical
characters), which is not necessarily the same as the number of bytes in the
string.
Digging Deeper
While the IETF RFC 8259 JSON standard recommends the use of UTF-8, other Unicode encodings are permitted. Therefore a JSON string may be represented in up to 4x the number of bytes as its number of code-points (assuming UTF-32 as the upper bound).
JSON Schema does not provide a mechanism to assert on the byte size of a JSON string, as this is an implementation-dependent property of the JSON parser in use.
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
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"minLength": 3
}
"foo"
"こんにちは"
"hi"
55