For example, need to validate field GRADE - not blank string (which can be converted to integer) or integer between 1 and 1000
-
just read the documentation of jsonschema you will find the examples theredeadshot– deadshot2022-04-29 18:35:43 +00:00Commented Apr 29, 2022 at 18:35
-
where? Read? Not found. Link please?Евгений В– Евгений В2022-04-29 18:40:27 +00:00Commented Apr 29, 2022 at 18:40
-
2this will help json-schema.org/learn/getting-started-step-by-stepdeadshot– deadshot2022-04-29 18:41:52 +00:00Commented Apr 29, 2022 at 18:41
Add a comment
|
1 Answer
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.
9 Comments
deadshot
how would you restrict the min and max numbers?
Clemens
So the person who just gives links to some documentation is now asking for details?
OneCricketeer
No, the question itself was asking for a range of numbers, not a pattern of single digits
Clemens
Please tell me how the property value can be of both types at the same time?
Ether
"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 $. |