0

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

3
  • just read the documentation of jsonschema you will find the examples there Commented Apr 29, 2022 at 18:35
  • where? Read? Not found. Link please? Commented Apr 29, 2022 at 18:40
  • 2
    this will help json-schema.org/learn/getting-started-step-by-step Commented Apr 29, 2022 at 18:41

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

9 Comments

how would you restrict the min and max numbers?
So the person who just gives links to some documentation is now asking for details?
No, the question itself was asking for a range of numbers, not a pattern of single digits
Please tell me how the property value can be of both types at the same time?
"pattern": "[0-9]" only checks that there is a digit somewhere in the string; to check that it consists only of digits, the pattern must be anchored with ^ and $.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.