The following example is a sample JSON schema:
{"type":"object",
"$schema": "http://json-schema.org/draft-03/schema",
"id": "#",
"required":false,
"properties":{
"OrgId": {
"type":"string",
"id": "OrgId",
"required":false
},
"metrics": {
"type":"array",
"id": "metrics",
"required":false,
"items": {
"type":"object",
"id": "0",
"required":false,
"properties":{
"name": {
"type":"string",
"id": "name",
"required":false
},
"valueTrend": {
"type":"array",
"id": "valueTrend",
"required":false,
"items": {
"type":"object",
"id": "0",
"required":false,
"properties":{
"date": {
"type":"string",
"id": "date",
"required":false
},
"val": {
"type":"string",
"id": "val",
"required":false
}
}
}
}
}
}
}
}
}
The schema defines the elements and attributes that can occur in a JSON document. The schema uses the JSON syntax to specify the hierarchy and sequence of elements, whether elements are required, the element type, and possible values.
The previous sample schema defines the following JSON input document:
{"OrgId": "ORG000000000001",
"metrics": [
{
"name": "COL1",
"valueTrend": [
{
"date": "2011-11-01",
"val": "122.456"
},
{
"date": "2011-11-02",
"val": "215.1"
}
]
},
{
"name": "COL2",
"valueTrend": [
{
"date": "2011-11-01",
"val": "122.456"
},
{
"date": "2011-11-02",
"val": "215.1"
}
]
}
]
}
If you trace through the schema, you can determine the relationship between the elements of the schema and input document.
The schema hierarchy contains the
metrics
object that nests the
valueTrend
array. The array contains the fields
date
and
val
that are of the
string
data type.