'JSON Schema format validation not working
I am using strict-rfc3339 as a dependency for my project and trying to validate the json schema date and date-time format. If i pass only date, it is working fine but when i pass as a JSON(Key-value pair) it is not validating.
Below is a sample
from jsonschema import validate, FormatChecker
# throws validation error as expected
validate( {"2001-02"}, {"type": "string", "format": "date"}, format_checker=FormatChecker())
# Doesn't throw error which is wrong
validate({"dob": "2001-02"}, {"dob": {"type": "string", "format": "date"}}, format_checker=FormatChecker())
Can someone help ? am i missing something ?
Solution 1:[1]
Your second schema is not written correctly. It should be:
{
"type": "object",
"properties": {
"dob": {
"type": "string",
"format": "date"
}
}
}
You can read more about specifying nested objects and properties at https://json-schema.org/understanding-json-schema/reference/object.html.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ether |
