JSON Schema with unknown property names

后端 未结 3 1848
太阳男子
太阳男子 2021-02-06 21:41

I want to have a JSON Schema with unknown property names in an array of objects. A good example is the meta-data of a web page:

      \"meta\": {
        \"typ         


        
3条回答
  •  别跟我提以往
    2021-02-06 22:04

    You can make constraints on properties not explicitly defined. The following schema enforces "meta" to be an array of objects whose properties are of type string:

    {
        "properties" : {
            "meta" : {
                "type" : "array",
                "items" : {
                    "type" : "object",
                    "additionalProperties" : {
                        "type" : "string"
                    }
                }
            }
        }
    }
    

    In case you just want to have an array of strings, you may use the following schema:

    {
        "properties" : {
            "meta" : {
                "type" : "array",
                "items" : {
                    "type" : "string"
                }
            }
        }
    }
    

提交回复
热议问题