简体   繁体   English

JSON 架构格式验证不起作用

[英]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.我正在使用 strict-rfc3339 作为我的项目的依赖项,并尝试验证 json 架构日期和日期时间格式。 If i pass only date, it is working fine but when i pass as a JSON(Key-value pair) it is not validating.如果我只传递日期,它工作正常,但是当我作为 JSON(键值对)传递时,它没有验证。

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?我错过了什么吗?

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 .您可以在https://json-schema.org/understanding-json-schema/reference/object.html阅读有关指定嵌套对象和属性的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM