Tejas Gokhale
Tejas Gokhale

Reputation: 1193

How to validate for length of an integer in Json Schema?

Simulator: https://www.jsonschemavalidator.net/s/L3FmJnoE

It looks like json schema validation does not check for regex patterns for integers. How to validate for length of an integer?

Json Schema -

{
  "$schema": "http://json-schema.org/draft/2019-09/schema",

  "title": "title",
  "type": "object",
  
  "properties": {
    "amount": {
      "type": "integer",
        "example": 199,
          "maxLength": 1,
            "pattern": "^[0-9]{1}$"
    }
  }

}

My Json which should fail validation but does not -

{
  
 "amount": 343434343434343434334343434343434
 
 }

Upvotes: 0

Views: 1361

Answers (1)

Clemens
Clemens

Reputation: 1817

Take a look at the maximum (specification) keyword and the related ones to set a maximum value for numbers. Regular expressions are only applied to string values (more details here).

(maxLength is also only applied to string values)

Upvotes: 1

Related Questions