Reputation: 81
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 ?
Upvotes: 0
Views: 1566
Reputation: 53966
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.
Upvotes: 2