diff --git a/content/2020-12/validation/maxLength.markdown b/content/2020-12/validation/maxLength.markdown index cb9c3c35..565758df 100644 --- a/content/2020-12/validation/maxLength.markdown +++ b/content/2020-12/validation/maxLength.markdown @@ -16,3 +16,49 @@ related: - vocabulary: format-annotation keyword: format --- + +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. + +* Applies only to string data types. +* Value must be a non-negative integer. +* 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 a valid string" +{{}} + +{{}} +"This description is too long" +{{}} + +{{}} +55 +{{}} \ No newline at end of file