We specify/write a schema to annotate and validate JSON documents.
In case, we only want to accept specific data.
If the data input would be nonsense, we will throw an error.
A schema is the document, that contains the description of the data.
# Overview
In this example we use a product catalog, that stores its data using JSON objects, like the following:
In this catalog, each product has its own identifier.
This object is readable for humans. But we don’t specifically know the structure, constraints, data types of for this set of JSON data.
So we gonna need a JSON schema.
# Basic Schema Keywords
# Properties Keyword
properties Is a validation keyword.
When you define properties, you create an object where each property represents a key in the JSON data that’s beeing validated.
# Required Properties
How to specify, that certain properties are required.
Add .>required keyword.
# Optional Properties
How to specify, that certain properties are optional.
Add properties>… keyword - do not set it as required.