Here is a JSON instance showing the start-time and end-time for a meeting:
{
"start time": "2015-02-19T08:00:00Z",
"end time": "2015-02-19T09:00:00Z"
}
I can specify the structure of that instance using JSON Schema: the instance must contain an object with a "start time" property and an "end time" property and each property must be a date-time formatted string. See below for the JSON schema. But what I cannot specify is this: the meeting must start before it ends. That is, the value of "start time" must be less than the value of "end time". Some people call this data dependency a co-constraint. In the XML world there is a wonderful, simple technology for expressing co-constraints: Schematron. I am wondering if there is an equivalent technology in the JSON world? What would you use to declaratively describe the relationship between the value of "start time" and "end time"? (Note: writing code in some programming language is not what I mean by "declaratively describe the relationships". I am seeking a declarative means to describe the data dependencies that are present in JSON documents, not procedural code.)
{
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {
"meeting": {
"type": "object",
"properties": {
"start time": { "type": "string", "format": "date-time"},
"end time": { "type": "string", "format": "date-time"}
},
"required": [ "start time", "end time" ],
"additionalProperties": false
}
},
"$ref": "#/definitions/meeting"
}