【问题标题】:How to make a JSON Schema for a JSON file in Oxygen如何在 Oxygen 中为 JSON 文件制作 JSON Schema
【发布时间】:2019-12-17 14:57:23
【问题描述】:

我有一个 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 schema jsonschema oxygenxml


    【解决方案1】:

    如果您想创建 JSON Schema,最好的方法是查看“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"
                ]
            }
        }
    }
    

    }

    最好的问候, 屋大维

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-25
      • 2016-02-27
      • 1970-01-01
      • 2020-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多