如何在 Oxygen 中为 JSON 文件制作 JSON 模式

How to make a JSON Schema for a JSON file in Oxygen

我有一个 Json 文件,我需要在 Oxygen 中为它编写一个 Scheme。

      "characters": [
        {
          "house":"Gryffindor",
          "orderOfThePhoenix":false,
          "name":"Cuthbert Binns",
          "bloodStatus":"unknown",
          "deathEater":false,
          "dumbledoresArmy":false,
          "school":"Hogwarts School of Witchcraft and Wizardry",
          "role":"Professor, History of Magic",
          "__v":0,
          "ministryOfMagic":false,
          "_id":"5a0fa67dae5bc100213c2333",
          "species":"ghost"
         }
    ],

        "spells": [
             {
              "spell":"Aberto",
              "effect":"opens objects",
              "_id":"5b74ebd5fb6fc0739646754c",
              "type":"Charm"
             }
],
"houses": [
     {
      "values": [
        "courage",
        "bravery",
        "nerve",
        "chivalry"
       ],
      "headOfHouse":"Minerva McGonagall",
      "mascot":"lion",
      "name":"Gryffindor",
      "houseGhost":"Nearly Headless Nick",
      "founder":"Goderic Gryffindor",
      "colors": [
        "scarlet",
        "gold"
       ],
      "school":"Hogwarts School of Witchcraft and Wizardry",
      "__v":0,
      "members": [
        "5a0fa648ae5bc100213c2332",
        "5a0fa67dae5bc100213c2333",
        "5a0fa7dcae5bc100213c2338",
        "5a123f130f5ae10021650dcc"
       ],
      "_id":"5a05e2b252f721a3cf2ea33f"
     },

可以肯定的是,当前 JSON 文件要大得多。如果有人可以发送相关链接,它也会有所帮助,或者某种教程。 你能帮我为它创建一个架构吗?

如果要创建 JSON 架构,最好的开始方式是查看 "json-schema.org" 教程。您可以在这里找到它们:

https://json-schema.org/learn/getting-started-step-by-step.html

https://json-schema.org/understanding-json-schema/

在下一版本的 Oxygen 中,将支持基于 JSON 实例或 XSD 创建 JSON 模式,但您需要检查创建的架构并根据您的需要对其进行自定义。 例如,对于您提供的实例,架构可能如下所示:

{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
    "characters": {"$ref": "#/definitions/characters_type"},
    "spells": {"$ref": "#/definitions/spells_type"},
    "houses": {"$ref": "#/definitions/houses_type"}
},
"definitions": {
    "characters_type": {
        "type": "array",
        "minItems": 0,
        "items": {
            "type": "object",
            "properties": {
                "house": {"type": "string"},
                "orderOfThePhoenix": {"type": "boolean"},
                "name": {"type": "string"},
                "bloodStatus": {"type": "string"},
                "deathEater": {"type": "boolean"},
                "dumbledoresArmy": {"type": "boolean"},
                "school": {"type": "string"},
                "role": {"type": "string"},
                "__v": {"type": "number"},
                "ministryOfMagic": {"type": "boolean"},
                "_id": {"type": "string"},
                "species": {"type": "string"}
            },
            "required": [
                "role",
                "bloodStatus",
                "school",
                "species",
                "deathEater",
                "dumbledoresArmy",
                "__v",
                "name",
                "ministryOfMagic",
                "_id",
                "orderOfThePhoenix",
                "house"
            ]
        }
    },
    "spells_type": {
        "type": "array",
        "minItems": 0,
        "items": {
            "type": "object",
            "properties": {
                "spell": {"type": "string"},
                "effect": {"type": "string"},
                "_id": {"type": "string"},
                "type": {"type": "string"}
            },
            "required": [
                "spell",
                "effect",
                "_id",
                "type"
            ]
        }
    },
    "values_type": {
        "type": "array",
        "minItems": 0,
        "items": {"type": "string"}
    },
    "houses_type": {
        "type": "array",
        "minItems": 0,
        "items": {
            "type": "object",
            "properties": {
                "values": {"$ref": "#/definitions/values_type"},
                "headOfHouse": {"type": "string"},
                "mascot": {"type": "string"},
                "name": {"type": "string"},
                "houseGhost": {"type": "string"},
                "founder": {"type": "string"},
                "colors": {"$ref": "#/definitions/values_type"},
                "school": {"type": "string"},
                "__v": {"type": "number"},
                "members": {"$ref": "#/definitions/values_type"},
                "_id": {"type": "string"}
            },
            "required": [
                "headOfHouse",
                "houseGhost",
                "mascot",
                "school",
                "founder",
                "values",
                "__v",
                "members",
                "name",
                "_id",
                "colors"
            ]
        }
    }
}

}

此致, 屋大维