Draft:JSON Schema
![]() | Draft article not currently submitted for review.
This is a draft Articles for creation (AfC) submission. It is not currently pending review. While there are no deadlines, abandoned drafts may be deleted after six months. To edit the draft click on the "Edit" tab at the top of the window. To be accepted, a draft should:
It is strongly discouraged to write about yourself, your business or employer. If you do so, you must declare it. Where to get help
How to improve a draft
You can also browse Wikipedia:Featured articles and Wikipedia:Good articles to find examples of Wikipedia's best writing on topics similar to your proposed article. Improving your odds of a speedy review To improve your odds of a faster review, tag your draft with relevant WikiProject tags using the button below. This will let reviewers know a new draft has been submitted in their area of interest. For instance, if you wrote about a female astronomer, you would want to add the Biography, Astronomy, and Women scientists tags. Editor resources
Last edited by Lovasoa (talk | contribs) 24 days ago. (Update) |
![]() | |
Filename extension |
.schema.json, .json |
---|---|
Internet media type |
application/schema+json |
Developed by | JSON Schema Working Group |
Type of format | Data interchange format |
Extended from | JSON |
Standard | Draft 2020-12 |
Open format? | Yes |
Website | json-schema |
JSON Schema is a specification for defining the structure and constraints of JSON (JavaScript Object Notation) data. It allows for validation, documentation, and interaction control of JSON-based formats, making it widely used in API development, data validation, and configuration management.[1]
Overview
JSON Schema provides a declarative way to describe JSON data. It enables validation by defining expected properties, types, formats, and constraints. JSON Schema is widely used to enforce consistency in data structures and improve interoperability between systems.[2]
Example
A sample JSON document and its schema:
JSON Data:
{
"productId": 1,
"productName": "A green door",
"price": 12.50,
"tags": ["home", "green"]
}
JSON Schema:
{
"$schema": "http://json-schema.org/draft/2020-12/schema",
"title": "Product",
"type": "object",
"properties": {
"productId": { "type": "integer" },
"productName": { "type": "string" },
"price": { "type": "number", "minimum": 0 },
"tags": { "type": "array", "items": { "type": "string" } }
},
"required": ["productId", "productName", "price"]
}
Features
Data Validation
JSON Schema validates data against predefined rules:
{
"type": "string",
"minLength": 5,
"pattern": "^[A-Z][a-z]+$"
}
This schema ensures a string starts with a capital letter, followed by lowercase letters, with minimum length of 5 characters.
Documentation
JSON Schema provides self-documenting metadata:
{
"title": "User",
"description": "A user account in the system",
"properties": {
"username": {
"description": "Unique identifier for the user"
}
}
}
The title, description, and property descriptions help developers understand the data structure.
Hypermedia Support
JSON Hyper-Schema extends JSON Schema for hypermedia-driven APIs:
{
"links": [
{
"rel": "self",
"href": "/users/{id}",
"templateRequired": ["id"]
}
]
}
This defines a link relation that constructs URLs using instance data, enabling HATEOAS principles.
Interoperability
JSON Schema works across different programming languages:
{
"$schema": "http://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"id": { "type": "integer" }
}
}
This schema can be used in JavaScript, Python, Java, or any language with JSON Schema validation support.
Versions
JSON Schema has undergone multiple revisions:
- Draft 4 (2013) – First widely adopted version.
- Draft 6 (2017) – Introduced new keywords and enhanced validation.
- Draft 7 (2018) – Added support for complex validation scenarios.
- Draft 2019-09 (2019) – Introduced dynamic references and new annotation features.
- Draft 2020-12 (2020) – The latest version, refining features and improving interoperability.[3]
Implementations
JSON Schema is supported in various programming languages:
- Python: The 'jsonschema' library provides validation capabilities.[4]
- JavaScript: The Ajv library offers efficient JSON Schema validation.[5]
- Java: Libraries such as Everit JSON Schema enable schema validation in Java applications.[6]
Applications
JSON Schema is commonly used in:
- API Development: Ensures consistency in request and response formats.
- Configuration Management: Validates configuration files for correctness.
- Data Storage: Helps define structured data models in NoSQL databases.[7]
Tools
Several tools facilitate working with JSON Schema:
- JSON Schema Validator: Online tool for validation.[8]
- JSON Builder: Interactive tool for creating and testing JSON structures.[9]
See also
References
- ^ "JSON Schema". json-schema.org. Retrieved 2025-03-30.
- ^ "What is a schema?". json-schema.org. Retrieved 2025-03-30.
- ^ "JSON Schema Specification". json-schema.org. Retrieved 2025-03-30.
- ^ "jsonschema". Python Package Index. Retrieved 2025-03-30.
- ^ "Ajv JSON Schema Validator". Retrieved 2025-03-30.
- ^ "Everit JSON Schema". GitHub. Retrieved 2025-03-30.
- ^ "JSON Schema Examples". MongoDB. Retrieved 2025-03-30.
- ^ "JSON Schema Validator". Newtonsoft. Retrieved 2025-03-30.
- ^ "JSON Builder". Retrieved 2025-03-30.