The most important keywords that can be used in this schema:
$schema
- The $schema keyword states that this schema is written according to the draft v4 specification
title
- the title of the schema
description
- the description of the schema
type
- defines the type of the JSON (object / array)
properties
- defines various keys and their value types, minimum and maximum values to be used in JSON file
required
- this keeps a list of required properties
minimum
- minimum acceptable value for the item
exclusiveMinimum
- If "exclusiveMinimum" is present and has boolean value true, the value must be greater than the value of "minimum"
maximum
- maximum acceptable value for the item
exclusiveMaximum
- If "exclusiveMaximum" is present and has boolean value true, the value must be lower than the value of "maximum"
multipleOf
- a numeric instance is valid against "multipleOf" if the result of the division of the instance by this keyword's value is an integer
maxLength
- the length of a string instance is defined as the maximum number of its characters
minLength
- the length of a string instance is defined as the minimum number of its characters
pattern
- a string instance is considered valid if the regular expression matches the instance successfully ... JSON schema example
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "Product",
  "description": "A product from Acme's catalog",
  "type": "object",
  "properties": {
    "id": {
      "description": "The unique identifier for a product",
      "type": "integer"
    },
    "name": {
      "description": "Name of the product",
      "type": "string",
      "minLength": 5,
      "maxLength": 20
    },
    "price": {
      "type": "number",
      "minimum": 0,
      "exclusiveMinimum": true
    }
  },
  "required": [
    "id",
    "name",
    "price"
  ]
}
JSON that the schema above belongs to:
{
    "id": 2,
    "name": "Lorem ipsum dolor si",
    "price": 0.5
}
If the JSON was:
{
    "id": 2.5,
    "name": "Lorem ipsum dolor sit amet",
    "price": -0.5
}
It would have the following errors:
- Invalid type. Expected Integer but got Number
- String 'Lorem ipsum dolor sit amet' exceeds maximum length of 20
- Float -0.5 is less than minimum value of 0
For validating the JSON with its schema, the resource below can be used
https://www.jsonschemavalidator.net/
by Valeri Tandilashvili
4 years ago
JSON
JSON schema
JSON Tutorial
0
Pro tip: use ```triple backticks around text``` to write in code fences