Introduction
JSON Schema is a JSON document that describes what other JSON documents must look like: which properties an object has, which are required, and what type and range each value may take. A validator checks a document against the schema, and editors use schemas to offer completion and show mistakes as you type.
Schemas are saved as ordinary .json files, often named
*.schema.json. Many configuration files, such as
package.json and tsconfig.json, have published schemas, and
OpenAPI descriptions of web APIs use JSON Schema for their data types.
Structure
A schema is a JSON object, or true or false. Its keys are
keywords. Common ones are:
$schema: the URL of the version of JSON Schema the file follows, such ashttps://json-schema.org/draft/2020-12/schema$id: the schema’s own URL, and$refto point at another schema or part of onetype:object,array,string,number,integer,booleanornullpropertiesandrequiredfor objects, anditemsfor arraysenum,minimum,maxLength,patternand others that limit valuesallOf,anyOf,oneOfandnotto combine schemas
Several drafts of the standard are in use, and the $schema value says which
one a file follows. Draft-07 and 2020-12 are the most common.
Also used for
- GeoJSON .json
- Hugging Face model config (config.json) .json
- Hugging Face tokenizer (tokenizer.json) .json
- JavaScript Object Notation .json
- Lottie animation .json
- Visual Studio Code settings .json
- npm package manifest (package.json) .json
Links
Software
- Visual Studio Code, which validates JSON files against their schemas (Windows, macOS, Linux)
- JSON Schema Store, a collection of schemas for common configuration files
Developers
- Ajv, JavaScript
- jsonschema, Python
Reference
- JSON Schema specification, json-schema.org