Friday, October 24, 2025

JSON Schema

JSON Schema is a content specification language used for validating the structure of a JSON data.It helps you specify the objects and what values are valid inside the object’s properties. JSON schema is useful in offering clear, human-readable, and machine-readable documentation.

Structure of a JSON Schema: Since JSON format contains an object, array, and name-value pair elements. Name-value pairs are used for providing schema processing elements as well as validating the JSON content. Schema processing elements include(not limited to).

  • $schema” To specify the version of JSON schema.
  • title and description: To provide information about the schema.
  • required: It’s an array of elements that indicates which elements should be present.
  • additionalProperties: To indicate whether existence of specified elements are allowed or not.

JSON content definition:

  • When a JSON object is defined, JSON schema uses name-value pair “type”:”object”
  • When arrays are defined, JSON schema uses the name-value pair “type”:”array”

Example:

{
  "$id": "https://example.com/person.schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Voters information",
  "type": "object",
  "properties": {
    "firstName": {
      "type": "string",
      "description": "The person's first name."
    },
    "lastName": {
      "type": "string",
      "description": "The person's last name."
    },
    "age": {
      "description": "Age in years which must be equal to or 
                      greater than eighteen in order to vote.",
      "type": "integer",
      "minimum": 18
    }
  }
}

Output:

{
  "firstName": "Indra",
  "lastName": "Sen",
  "age": 20
}

The above JSON schema contains the following:

  • $id keyword
  • $schema keyword
  • title annotation keyword
  • properties validation keyword
  • Three keys: firstName, lastName and age each with their own description keyword.
  • type instance data model (see above)
  • minimum validation keyword on the age key.
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS