Json模式-验证无限递归结构


Json Schema - Validate an infinite recursive structure

我正在尝试使用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":
                             [
                                 {
                                      ...
                                 }
                             ]
                     }
                 ] 
             }
         ]
     }
 ]

questions属性总是可以出现在questions属性....中我如何验证它?

感谢您的回答

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

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