2

I'm trying to validate a json object using the "justinrainbow/json-schema" package for php.

Here's the json that i'm trying to validate:

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

The questions property can always be present inside questions property .... How can i validate it?

Thank you for your answers

Ricardo Machado
  • 787
  • 1
  • 8
  • 16
  • Possible duplicate of [JSON Schema - Recursive Schema Definition](http://stackoverflow.com/questions/20752716/json-schema-recursive-schema-definition) – jruizaranguren Sep 15 '16 at 10:01

1 Answers1

2

You can use $ref to define a recursive structure.

{
  "type": "object",
  "properties": {
    "type": { "type": "string" },
    "name": { "type": "string" },
    "questions": { "type": "array", "items": { "$ref": "#"} }
  }
}
Jason Desrosiers
  • 22,479
  • 5
  • 47
  • 53