json模式日期时间不正确检查 [英] json schema date-time does not check correctly

查看:469
本文介绍了json模式日期时间不正确检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JSON和一个JSON模式

I have a JSON and a JSON-schema

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,则模式不会注意到它不再是日期时间。

The JSON gets validated by the JSON-schema. However if I change the field aaa to "bla" the schema does not notice that it is not a date-time any longer.

我错过了模式中的任何内容?

Did I miss anything in the schema?

推荐答案

Python jsonschema 模块,在调用 validate()

For the Python jsonschema module, specify the format checker when calling validate():

jsonschema.validate(json, schema, format_checker=jsonschema.FormatChecker())

要验证日期时间格式,需要安装strict-rfc3339模块。

To validate a date-time format, the strict-rfc3339 module needs to be installed.

请参阅验证格式

这篇关于json模式日期时间不正确检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆