I'm using jsonschema to validate my python dictionary. I' trying to validate a datetime
value but I'm not sure how to do it.
Here's what I have so far, which results in an error because jsonschema doesn't have a datetime
type:
order = {
"name": "shirt",
"order_datetime": datetime.datetime(2018, 1, 18)
}
schema = {
"title": "Order",
"type": "object",
"required": ["name", "order_datetime"],
"properties": {
"name": {
"type": "string"
},
"order_datetime": {
"type": "datetime"
}
}
}
from jsonschema import validate
validate(order, schema)
The error is jsonschema.exceptions.SchemaError: 'datetime' is not valid under any of the given schemas
. How can I validate this correctly?
'date-time'
. And looking at one of the schemas it's described as "a valid date-time string", not adatetime
instance. – Steven Rumbalskinumber
you would extenddate-time
. – Steven Rumbalskischema
. – Steven Rumbalski