Евгений В
Евгений В

Reputation: 1

How to define different possible types for one field in JSON Schema?

For example, need to validate field GRADE - not blank string (which can be converted to integer) or integer between 1 and 1000

Upvotes: 0

Views: 73

Answers (1)

Clemens
Clemens

Reputation: 1817

The most basic definition would be:

      "GRADE": {
        "type": ["string", "integer"],
        "pattern": "^[0-9]+$"
      }

Take a look at the pattern keyword as described in detail here: https://json-schema.org/understanding-json-schema/reference/string.html#id6

You can define a regular expression that meets your exact requirements for the GRADE field.

Upvotes: 1

Related Questions