基于json对象创建JSON模式

时间:2016-09-12 21:29:39

标签: json jsonschema json-schema-validator json-schema-defaults

鉴于以下JSON对象,我如何构建json架构? Product1,Product2和Product3是动态的"键"我可以有更多这样的东西,但每个人都会有相同的价值#34;具有所需键的对象,如packageId1,packageId2,packageId3及其对应的值作为字符串。

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

1 个答案:

答案 0 :(得分: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" }
      }
    }
  }
}