Json Schema - 验证无限递归结构

时间:2016-09-13 12:11:21

标签: php json validation jsonschema

我正在尝试使用php的“justinrainbow / json-schema”包验证json对象。

这是我想要验证的json:

{
"questions": [
     {
        "type": "section",
        "name": "Section one",
        "questions": [
            {
                "type": "section",
                "name": "Subsection 1.1" 
                "questions":[
                    {
                        "type": "section",
                        "name": "Subsection 1.1" 
                        "questions":
                             [
                                 {
                                      ...
                                 }
                             ]
                     }
                 ] 
             }
         ]
     }
 ]

问题属性总是存在于问题属性中.... 我该如何验证呢?

感谢您的回答

1 个答案:

答案 0 :(得分:2)

您可以使用$ref来定义递归结构。

{
  "type": "object",
  "properties": {
    "type": { "type": "string" },
    "name": { "type": "string" },
    "questions": { "type": "array", "items": { "$ref": "#"} }
  }
}
相关问题