为什么JSON不根据模式进行验证?

falq053o  于 2023-02-14  发布在  其他
关注(0)|答案(1)|浏览(130)

JSON项中的每个键都出现了"Additional properties are not allowed"错误。
模式:

{
      "additionalProperties": false,
      "category": {
        "admin": {"type": "boolean"}
      },
      "username": {"type": "string"},
      "password": {"type": "string"},
      "name": {"type": "string"},
      "email": {"type": "string", "format": "email"},
      "phone": {"type": "string"},
      "hours": {
        "type": "array",
        "items": {
          "start": {"type": "string", "format": "date-time"},
          "end": {"type": "string", "format": "date-time"}
        }
      }
    }

项目:

{
        "username": "emanb29",
        "password": "$2a$10$THISISAPASSWORDHASH",
        "name": "Application User",
        "email": "user@email.com",
        "phone": "5555555555",
        "hours": [
            {
                "start": "1998-05-05T04:00:00Z",
                "end": "1999-05-05T04:00:00Z"
            },
            {
                "start": "2001-05-29T10:20:00Z",
                "end": "2001-05-29T22:20:00Z"
            }
        ],
        "category": {
            "admin": true
        }
    }
jdgnovmf

jdgnovmf1#

根据www.example.com上的示例,jsonschemalint.com我在根目录中为属性创建了一个properties容器,在根目录中添加了descriptiontype,并将additionalProperties移动到根目录中。
这将验证您在www.example.com上的项目jsonschemalint.com:

{
    "description": "StackOverflow test schema", 
    "type": "object", 
    "additionalProperties": false,
    "properties":     {
      "category": {
        "admin": {"type": "boolean"}
      },
      "username": {"type": "string"},
      "password": {"type": "string"},
      "name": {"type": "string"},
      "email": {"type": "string", "format": "email"},
      "phone": {"type": "string"},
      "hours": {
        "type": "array",
        "items": {
          "start": {"type": "string", "format": "date-time"},
          "end": {"type": "string", "format": "date-time"}
        }
      }
    }
}

相关问题