What is WoT: JSON Schema introduction
by the Web of Things Community Group
In this video, we will briefly explain Schema Languages and then move to the JSON Schema since it is the one that describes and validates JSON, which is important in the scope of Web of Things. The corresponding web page of this video is at https://w3c.github.io/wot-cg/tutorials/whatiswot/docs/preliminary/json-schema/intro.
Video
Transcript
In this video, we will briefly explain Schema Languages and then move to the JSON Schema since it is the one that describes and validates JSON, which is important in the scope of Web of Things.
Let us explain what is a schema.
Many payload formats offer a way to describe what a payload instance should look like. Generally, these are called Schema Languages. For example, JSON Schema, XML Schema, GraphQL Schema Definition Language.
Now let's take JSON Schema.
JSON Schema is a JSON document used to describe and validate how JSON payload instance should look like.
The main idea is to enable senders such as clients to understand how the request should be and for the receiver to automatically validate the payloads.
Although it is also a JSON, it is metadata and not part of the payloads.
We can see some basic JSON Schema examples here. type "array" tells that the schema accepts JSON documents that are arrays. This can be defined for other types in JSON as well, such as, string, number, boolean, and null.
Thus, in the receiver end, you can do this validation process to validate. This is an example how it could look like in JavaScript.
It can look different in other programming languages. For instance: Python, Java and C++ Of course, way more advanced validations are possible with JSON Schema such as: Regular expressions, URIs, length of a string Max/min for numbers, IP addresses, email addresses Or you can specify amount of the items and allowed types in an array, as well as required properties and amount of properties in an object.
You can proceed to the next tutorial by clicking on the card or the video description.