HOME
About this site
This site is intended to be a complete and understandable guide to JSON Schema. You can find an exhaustive specification with intuitive examples. The people behind this project form part of the Computer Science Department at PUC Chile, and belong to the Center for Semantic Web Research.
What is JSON?
JSON (JavaScript Object Notation) is a file format commonly used for sharing information over the Web. JSON files are lightweight and easy to read both by machines and developers. This has made JSON the most popular file format for client-server communication. The next example JSON file contains information about the famous Chilean football player Alexis Sanchez.
alexis_sanchez.json
{
"first_name": "Alexis",
"last_name": "Sanchez",
"age": 27,
"club": {
"name": "Arsenal FC",
"founded": 1886
}
}
What is JSON Schema?
A JSON Schema is a file that specifies the structure of JSON documents used by a certain application. For example, when sharing information about football players, one would like to ensure that a JSON document corresponding to a player has a given structure. A JSON Schema is a JSON document in which some words (keywords) have a predefined meaning. The next example schema specifies documents like alexis_sanchez.json.
player_schema.json
{
"type": "object",
"properties": {
"first_name": { "type": "string" },
"last_name": { "type": "string" },
"age": { "type": "integer" },
"club": {
"type": "object",
"properties": {
"name": { "type": "string" },
"founded": { "type": "integer" }
},
"required": ["name"]
}
},
"required": ["first_name", "last_name", "age", "club"]
}
Intuitively, using this schema we are saying that our JSON documents have to have a property "first_name" with a string value, a property "last_name" and so on. Additionally, we also require that some of the information, like "first_name", "last_name", "age" and "club" details are present in each document conforming to the schema, while other properties may be ommited.
Why to use JSON Schema
There are several reasons to use a schema when storing data or sharing data over the Web. Some of the benefits:
- Filtering content: When storing files or receiving files over the web, programmers always want to ensure the data comes in the right format. JSON Schema allows for on-the-fly validation of JSON files.
- Compression: If a schema is known by both the source and the target when sharing information, the network load can be decreased by compressing property names.
- Standardization: Today many APIs receive JSON files as instructions. For example, you can send a JSON file to Twitter's API indicating you want the last five tweets of a user. To use one of these APIs, you need to read the documentation provided by the API developers. Sometimes this documentation is messy and hard to read. If APIs defined a JSON Schema for input files, one could easily understand the allowed JSON files. Moreover, this allows for creating automation tools. For example, given a JSON Schema one could automatically generate a set of example API calls.