Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

A valid example is when the field called "value" is of a string and between 2 and 3 characters in length. 

In the JSON schema example below, the following fields are required to be included in each record:

  • brand
  • model
  • color
  • date
Code Block
languagejs
{
  "required": [
    "brand",
    "color",
    "model",
    "date"
  ],
  "properties": {
    "value": {
      "type": "string",
      "minLength": 2,
      "maxLength": 3
    }
  }
}

The following record matches all of the criteria:

Code Block
languagejs
{
    "brand": "brand1",
    "model": "modelA",
    "color": "red",
    "date":  "20 March 2019",
    "value": "cat" 
}

The following record is discarded because hamster has more than 3 characters:

Code Block
languagejs
{
    "brand": "brand1",
    "model": "modelA",
    "color": "red",
    "date":  "20 March 2019",
    "value": "hamster" 
}

Pattern validation is done by specifying specific expressions that correlate with the desired functionality. In this example the code checks for the presence of 6 digits and 3 Uppercase characters: 

Code Block
languagejs
{
   "type":"string",
   "pattern":"\\d{6}[A-Z]{3}"
}

Another pattern validation example checks for the presence of a specific email address format: 

Code Block
languagejs
{
   "type":"string",
   "pattern":".+@.+\\..+"
}

For further information on how to use JSON schema, see https://json-schema.org/.