JSON Schema can most definitely handle recursive structures as of draft-03. Draft-03 introduced the "$ref" attribute, which allows a schema to reference another schema (or itself) to validate against. In the case of a filesystem hierarchy, assume a JSON representation of the data as follows:
{
"type" : "folder",
"name" : "documents",
"contents" : [
{
"type" : "folder",
"name" : "testDir",
"contents" : []
},
{
"type" : "file",
"name" : "test.txt"
}
]
}
As JSON schema that represents this data would be as follows:
{
"type" : "object",
"id" : "folder",
"additionalProperties" : false,
"properties" : {
"name" : { "required" : true, "type" : "string" },
"type" : { "required" : true, "type" : "string", "enum" : ["folder"] },
"contents" : {
"required" : true,
"type" : "array",
"additionalItems" : false,
"items" : [
{ "$ref" : "folder" },
{
"type" : "object",
"id" : "file",
"additionalProperties" : false,
"properties" : {
"name" : { "required" : true, "type" : "string" },
"type" : { "required" : true, "type" : "string", "enum" : ["file"] }
}
}
]
}
}
}