minLength : Integer

minLength

Integer

A 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
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 is used to specify the minimum length of a string instance. It defines the minimum number of characters that a valid string must have to satisfy the schema.

  • String length is counted in characters, not bytes.
  • Validation succeeds if the string length is greater than or equal to the specified minLength.

Examples

Schema requiring minimum string length of 5 Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "string",
  "minLength": 5
}
Valid An instance with a string length greater than or equal to 5 is valid Instance
"This is a valid string"
Invalid An instance with a string length less than 5 is invalid Instance
"foo"
Schema which allows either a string with at least 3 characters or a numeric value Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": [ "string", "number" ],
  "minLength": 3
}
Valid An instance with a string length greater than or equal to 3 is valid Instance
"foo"
Invalid An instance with a string length less than 3 is valid Instance
"hi"
Valid An instance with a numeric value is valid Instance
55