Ruby 如果json有多个数据集,如何编写json模式

Ruby 如果json有多个数据集,如何编写json模式,ruby,json,jsonschema,Ruby,Json,Jsonschema,我是这个json模式的新手,如果它只有一个如下所示的数据集,我就能够编写json模式 { "employees": [ { "id": 1, "name": "aaa" } } 这方面的json模式示例如下 { "type" : "object", "required" : ["employees"], "properties" : {

我是这个json模式的新手,如果它只有一个如下所示的数据集,我就能够编写json模式

{
    "employees": [
        {
            "id": 1,
            "name": "aaa"
        }
}
这方面的json模式示例如下

{   
        "type" : "object",
            "required" : ["employees"],
            "properties" : {        
                "employees" : { "type" : "Array",
                                "items" : [
                                "properties" : {
                                                    "id" : {"type" : "integer"},
                                                    "name" : {"type" : "string"},                                                   
                                                },
                                            "required" : ["id","name"]
                                            ]
                                }
                            }
}
但如果我们有多个数据集,我就不得不用ruby编写json模式

{
    "employees": [
        {
            "id": 1,
            "name": "aaa"
        },
        {
            "id": 2,
            "name": "bbb"
        },
        {
            "id": 3,
            "name": "cccc"
        },
        {
            "id": 4,
            "name": "ddd"
        },
        {
            "id": 5,
            "name": "eeee"
        }
    ]
}

如果同一个模式有多个数据集来验证响应主体,那么有人能帮我编写json模式吗

{
  "type": "object",
  "required": ["employees"],
  "properties": {
    "employees": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": { "type": "integer" },
          "name": { "type": "string" }
        },
        "required": ["id", "name"]
      }
    }
  }
}
你真的很接近。
items
关键字有两种形式。
项的值可以是架构或架构数组(1)

如果
items
是一个模式,则表示数组中的每个项都必须符合该模式。这是在这种情况下有用的形式

如果
items
的值是一个模式数组,则它描述一个元组。例如,此模式

{
  "type": "array",
  "items": [
    { "type": "boolean" },
    { "type": "string" }
  ]
}
会验证这一点

[true, "foo"]

  • 您可以编写散列,然后将其转换为JSON,但员工数据集的计数始终不相同,如果他们在dbArgghh中插入新记录,则该值将增加。你比我早很多。我发现正确的筑巢非常耗时。@json谢谢你的帮助