JSON schema provides a JSON vocabulary for defining and validating JSON instances.
Each schema includes one or more key-value pairs or keywords, including
a type
keyword set to a JSON simple value (null
, boolean
, number
, integer
or string
),
array
or object
as defined in JSON data:
All schemas may include the following keywords:
description
keyword to provide a definition for this type or property.$id
keyword to provide a base URL for referencing this schema, type or property.$ref
keyword to provide a JSON pointer to another schema, type or property,Other keywords are specific to the type
as follows:
multipleOf
: limit the value to be a multiple of a given numberminimum
,exclusiveMinimum
, maximum
,exclusiveMaximum
: restrict the range of valuesminLength
,maxLength
: limit the length of the stringpattern
: require the value to satisfy a regular expressionformat
: require the value to match a certain format(e.g. date-time
, email
, ipv4
, uri
)items
restricted with the following keywords:
type
: limit the type of each itemenum
: define the allowable values of each item with an arrayminItems
, maxItems
: limit the number or itemsuniqueItems
: require each item to be uniqueproperties
: list properties that MAY be included in the objectrequired
: list properties that MUST be included in the objectadditionalProperties
: allow properties that are not listed in the type definitionminProperties
, maxProperties
: limit the number of properties in the objectpatternProperties
: define types for properties based on their namedependencies
: add restrictions if certain conditions are metIn addition, schemas may be combined with the following keywords:
allOf
: must be valid against all of the subschemasanyOf
: must be valid against any of the subschemasoneOf
: must be valid against exactly one of the subschemasAn simple example of a JSON schema to request a court hearing is:
{
"$id": "https://example.com/request",
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"additionalProperties": false,
"definitions": {
"request:RequestMessage": {
"$ref": "#/definitions/request:RequestMessageType",
"description": "A request for the schedule of upcoming events in a court"
},
"request:RequestMessageType": {
"additionalProperties": false,
"description": "A request for the schedule of upcoming events in a court",
"properties": {
"request:CaseTypeCode": {
"description": "A certain case type.",
"type": "string",
"enum": ["civil", "criminal", "traffic"]
},
"request:CourtID": {
"description": "The identifier for a court of law in which the case is being tried.",
"type": "integer",
"minimum": 1,
"maximum": 9
},
"request:CourtName": {
"description": "A court of law in which the case is being tried.",
"type": "string"
},
"request:HearingDate": {
"description": "The requested date of the hearing.",
"type": "string",
"format": "date"
},
"request:InitialApperanceIndicator": {
"description": "Indicates whether this will be an initial appearance in this case.",
"type": "boolean"
}
},
"required": [
"request:CaseTypeCode",
"request:CourtID",
"request:CourtName",
"request:HearingDate",
"request:InitialApperanceIndicator"
],
"type": "object"
}
},
"properties": {
"request:RequestMessage": {
"$ref": "#/definitions/request:RequestMessageType",
"description": "A request for the schedule of upcoming events in a court"
},
"@context": { }
},
"required": [
"@context",
"request:RequestMessage"
]
}
An example of a JSON request based on the schema is:
{
"@context": {
"request": "https://example.com/request#"
},
"request:RequestMessage": {
"request:CaseTypeCode": "civil",
"request:CourtID": 3,
"request:CourtName": "Springfield Circuirt Court",
"request:HearingDate": "2019-01-02",
"request:InitialApperanceIndicator": true
}
}
A complete NIEM-conforming example of a JSON court scheduling exchange adapted from the LegalXML Electronic Court Filing (ECF) 5.0 specification is also available