Using jsonschema to validate that a key has a unique value within an array of objects?

♀尐吖头ヾ 提交于 2019-12-06 11:26:32

I found the alternative method of using a schema that allows arbitrary properties. The only caveat is that JSON allows duplicate object keys, but duplicates will override their previous instances. The array of objects with the key "Name" can be converted to an object with arbitrary properties:

For example, the following JSON:

"test_object": {
    "name1": {
        "Desc": "Description 1"
    },
    "name2": {
        "Desc": "Description 2"
    }
}

would have the following schema:

{
    "type": "object",
    "properties": {
        "test_object": {
            "type": "object",
            "patternProperties": {
                "^.*$": {
                    "type": "object",
                    "properties": {
                        "Desc": {"type" : "string"}
                    },
                    "required": ["Desc"]
                }
            },
            "minProperties": 1,
            "additionalProperties": false
        }
    },
    "required": ["test_object"]
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!