JSON Schema for tree structure

前端 未结 1 1067
小鲜肉
小鲜肉 2020-12-19 23:17

I have to build tree like structure of Json data.Each node has an id (an integer, required), a label (a string, optional), and an array of child nodes (optional). Can you he

相关标签:
1条回答
  • 2020-12-19 23:26

    A schema for this structure only needs a definition of a node and a reference to that node. The property Children (renamed from Child) references the node as well.

    Here's the schema:

    {
      "$schema": "http://json-schema.org/draft-04/schema#",
      "$ref": "#/definitions/node",
      "definitions": {
        "node": {
          "properties": {
            "Id": {
              "type": "integer"
            },
            "Label": {
              "type": "string"
            },
            "Children": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/node"
              }
            }
          },
          "required": [
            "Id"
          ]
        }
      }
    }
    
    0 讨论(0)
提交回复
热议问题