Skip to content

Validation of string byte-length? #377

Answered by jdesrosiers
joaohaas asked this question in Q&A
Discussion options

You must be logged in to vote

Unfortunately, there's no way to validate this with JSON Schema. I've always thought that the way this keyword is defined (counting visible characters) made it practically useless. Almost always, the reason to constrain the length of a string in a schema is to ensure that it will fit in some space in memory (usually a cell in a relational database table). I'd even call maxLength a foot-gun because people use this keyword all the time to check that their strings will fit in their database tables and don't realize that it won't always work.

I'd support adding a new keyword that constrains the maximum size of strings.

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
4 replies
@joaohaas
Comment options

@jdesrosiers
Comment options

@karenetheridge
Comment options

@SorinGFS
Comment options

Answer selected by joaohaas
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants