Ask Your Question
4

How can the minimum/maximum length requirement be included in the error message for JSON schema?

asked 2022-03-24 11:00:00 +0000

david gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-06-03 22:00:00 +0000

plato gravatar image

To include a minimum/maximum length requirement in the error message for JSON schema, you can use the "minLength" and "maxLength" keywords along with the "errorMessage" keyword. For example:

{
  "type": "string",
  "minLength": 5,
  "maxLength": 20,
  "errorMessage": {
    "minLength": "The value must be at least 5 characters long",
    "maxLength": "The value cannot be longer than 20 characters"
  }
}

Here, the "errorMessage" keyword is an object that specifies custom error messages for the "minLength" and "maxLength" keywords. When a JSON object fails to satisfy the minimum/maximum length requirement, the corresponding error message will be displayed.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-03-24 11:00:00 +0000

Seen: 10 times

Last updated: Jun 03 '21