我有一个JSON和一个JSON模式
JSON:
{
"aaa": "4000-02-01 00:00:00"
}
JSON模式:
{
"$schema": "http://json-schema.org/draft-04/schema",
"type": "object",
"properties": {
"aaa": {
"type": "string",
"format": "date-time"
}
}, "required": ["aaa"]
}
JSON通过JSON模式验证。但是,如果我将
aaa
字段更改为“bla”,则架构不会注意到它不再是日期时间。我错过了架构中的任何内容吗?
最佳答案
对于Python的jsonschema库,在调用validate
时指定格式检查器:
jsonschema.validate(data, schema, format_checker=jsonschema.FormatChecker())
要验证日期时间格式,应安装strict-rfc3339软件包。
参见Validating Formats。