What is JSON Schema?
JSON Schema is a vocabulary that allows you to annotate and validate JSON documents. It defines the structure and constraints of JSON data, making it easier to ensure that your data adheres to specific formats and rules.
Create a Schema
Let's start with a simple JSON object and then create a schema for it. If we look at the following JSON object, there's no way to tell if the data is valid or not or what the expected structure is.
To create a schema for this JSON object, there are some keywords we need to define.
$schema
: The version or standard of the JSON schema being used.$id
: URI for the schema, which can be used to reference it for internal and external JSON documents.title
anddescription
: It mainly provides metadata about the schema.type
: Defines the first constraint of the JSON data.
exclusiveMinimum
: This keyword specifies that the value must be greater than the specified number, in this case, 0.required
: This keyword specifies which properties are required in the JSON object.minItems
: This keyword specifies that the array must contain at least one item.uniqueItems
: This keyword specifies that all items in the array must be unique.
Create a Nested Data Structure
Of course, JSON data can be more complex and can contain nested objects or arrays. Let's extend our schema to include a nested structure for the student's address.
Use external schemas
You can also reference or use external schemas to keep your schema modular and reusable.
To reference this external schema in your main schema, you can use the $ref
keyword.
Written by
KarChunT
Last Updated
Sat Jun 21 2025
Tags