JSON Schema

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:

  • Adescription keyword to provide a definition for this type or property.
  • An $id keyword to provide a base URL for referencing this schema, type or property.
  • A $ref keyword to provide a JSON pointer to another schema, type or property,

Other keywords are specific to the type as follows:

  • Numbers and integers may be restricted with the following keywords:
    • multipleOf: limit the value to be a multiple of a given number
    • minimum,exclusiveMinimum, maximum,exclusiveMaximum: restrict the range of values
  • Strings may be restricted with the following keywords:
    • minLength,maxLength: limit the length of the string
    • pattern: require the value to satisfy a regular expression
    • format: require the value to match a certain format(e.g. date-time, email, ipv4, uri)
  • Arrays may contain one or more items restricted with the following keywords:
    • type: limit the type of each item
    • enum: define the allowable values of each item with an array
    • minItems, maxItems: limit the number or items
    • uniqueItems: require each item to be unique
  • Objects may contain one or more properties restricted with the following keywords:
    • properties: list properties that MAY be included in the object
    • required: list properties that MUST be included in the object
    • additionalProperties: allow properties that are not listed in the type definition
    • minProperties, maxProperties: limit the number of properties in the object
    • patternProperties: define types for properties based on their name
    • dependencies: add restrictions if certain conditions are met

In addition, schemas may be combined with the following keywords:

  • allOf: must be valid against all of the subschemas
  • anyOf: must be valid against any of the subschemas
  • oneOf: must be valid against exactly one of the subschemas

An 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