How can i write the json schema if json has multiple data set

后端 未结 1 609
粉色の甜心
粉色の甜心 2021-01-29 07:08

I am new to this json schema , i am able to write json schema if it has only one data set like below

{
    \"employees\": [
        {
            \"id\": 1,
             


        
相关标签:
1条回答
  • 2021-01-29 07:23

    Here is the schema you are looking for.

    {
      "type": "object",
      "required": ["employees"],
      "properties": {
        "employees": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": { "type": "integer" },
              "name": { "type": "string" }
            },
            "required": ["id", "name"]
          }
        }
      }
    }
    

    You were really close. The items keyword has two forms. The value of items can be a schema or an array of schemas(1).

    If items is a schema, it means that every item in the array must conform to that schema. This is the form that is useful in this case.

    If the value of items is an array of schemas, it describes a tuple. For example, this schema ...

    {
      "type": "array",
      "items": [
        { "type": "boolean" },
        { "type": "string" }
      ]
    }
    

    would validate this ...

    [true, "foo"]
    
    1. http://json-schema.org/latest/json-schema-validation.html#anchor37
    0 讨论(0)
提交回复
热议问题