JSON Schema with unknown property names

后端 未结 3 1852
太阳男子
太阳男子 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:02

    Use patternProperties instead of properties. In the example below, the pattern match regex .* accepts any property name and I am allowing types of string or null only by using "additionalProperties": false.

      "patternProperties": {
        "^.*$": {
          "anyOf": [
            {"type": "string"},
            {"type": "null"}
          ]
        }
      },
      "additionalProperties": false
    

提交回复
热议问题