如何为此JSON模式编写数据?

时间:2016-09-07 20:14:16

标签: json jsonschema

我试图使用在线虚假数据生成器从我的json架构生成示例数据,但由于某些原因它不接受我的架构,但我没有看到它有什么问题。我想手动完成,但我不确定我是否正确操作。以下数据是否与架构匹配?

模式

{
  "$schema": "http://somesite.com",
  "description": "mychema",
  "type": "object",
  "properties": {
    "Form": {
      "description": "form properties",
      "type": "object",
      "properties": {
        "formproperty": {
          "description": "test value",
          "type": "string"
        }
      }
    },
    "FormElements": {
      "description": "form elements and their properties",
      "type": "array",
      "items": {
        "title": "Form Element",
        "type": "object",
        "properties": {
          "id": {
            "description": "The unique identifier",
            "type": "string"
          },
          "positionX": {
            "description": "The X coordinate",
            "type": "number"
          },
          "positionY": {
            "description": "The Y coordinate",
            "type": "number"
          },
          "elementSpecificProperties": {
            "description": "unique properties",
            "type": "object",
            "oneOf": [
              { "$ref": "#/definitions/Label" }
            ]
          }
        }
      }

    }
  },

        "definitions": {
          "Label": {
          "type": "object",
          "properties": {
            "value": {
              "description": "",
              "type": "string"

            }
          }
        }
      }
}

数据

{
    "Form":{
        "formproperty": "test"
    },
    "FormElements":[
        {
            "id": "1",
            "positionX":  20,
            "positionY":  15,

            "value": "testing1"
        },
        {
            "id": "2",
            "positionX":  5,
            "positionY":  12,

            "value": "testing2"
        }
    ]
}

1 个答案:

答案 0 :(得分:0)

我可以确认您的架构是有效的,并且数据对架构有效。但是,根据您的架构,我认为您的意思是这个。

{
  "Form": {
    "formproperty": "test"
  },
  "FormElements": [
    {
      "id": "1",
      "positionX": 20,
      "positionY": 15,
      "elementSpecificProperties": {
        "value": "testing1"
      }
    },
    {
      "id": "2",
      "positionX": 5,
      "positionY": 12,
      "elementSpecificProperties": {
        "value": "testing2"
      }
    }
  ]
}