Correct JSON Schema for an array of items of different type

后端 未结 5 1311
渐次进展
渐次进展 2020-12-16 10:56

I have an unordered array of JSON items. According to the specification http://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.5 the json schema below will only vali

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-16 11:18

    As a response to user Vdex: this is not equivalent, what you wrote means that array elements occur in this particular order within the array.

    Subject to a correct implementation, if you use this schema validator.

    With this schema:

    {
      "$schema": "http://json-schema.org/draft-04/schema#",
      "type": "array",
      "items": [
        {
          "type": "boolean"
        },
        {
          "type": "number"
        },
        {
          "type": "string"
        }
      ]
    }
    

    This JSON will be validated:

    [
      true,
      5,
      "a",
      "6",
      "a",
      5.2
    ]
    

    But not this one:

    [
      5,
      true,
      "a",
      "6",
      "a",
      5.2
    ]
    

    Thus, the objective is totally different from keywords like "oneOf".

提交回复
热议问题