0

给定以下 JSON 对象,我该如何构建 json 模式?Product1、Product2 和 Product3 是动态“键”,我可以有更多类似的,但它们中的每一个都将具有相同的“值”对象,所需的键为 packageId1、packageId2、packageId3,它们对应的值为字符串。

{
  "Product1": {
    "packageId1": "basicpackage",
    "packageId2": "basicpackage",
    "packageId3": "basicpackage"
  },
  "Product2": {
    "packageId1": "newpackage",
    "packageId2": "newpackage",
    "packageId3": "newpackage"
  },
  "Product3": {
    "packageId1": "thirdpackage",
    "packageId2": "thirdpackage",
    "packageId3": "thirdpackage"
  }
}
4

1 回答 1

1

我想我知道该怎么做了。如果有人感兴趣,我正在回答我自己的问题。另外,我欢迎更好的建议。

{
  "title": "JSON Schema for Fulfillment Config",
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "patternProperties": {
    ".{1,}": {
      "type": "object",
      "properties": {
        "packageId1": { "type": "string" },
        "packageId2": { "type": "string" },
        "packageId3": { "type": "string" }
      }
    }
  }
}
于 2016-09-13T22:03:25.170 回答