William William - 1 year ago 123
JSON Question

JSON Schema - Recursive Schema Definition

I have a JSON Schema

{
'description': 'TPNode',
'type': 'object',
'id': 'tp_node',
'properties': {
'selector': {
'type': 'string',
'required': true
},
'attributes': {
'type': 'array',
'items': {
'name': 'string',
'value': 'string'
}
},
'children': {
'type': 'array',
'items': {
'type': 'object',
'$ref': '#'
}
},
'events': {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'type': {
'type': 'string'
},
'handler': {
'type': 'object'
},
'dependencies': {
'type': 'array',
'items': {
'type': 'string'
}
}
}
}
}
}
}


What I'm trying to express in the children property is that it's an array of objects with the same exact schema. Is this the correct way to describe it?

Answer Source

Use the id of the schema you need to reference

'$ref': 'tp_node'

See here: http://json-schema.org/latest/json-schema-core.html#anchor30

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download