Understanding JSON Schema
As APIs grow in complexity, ensuring that the data being sent and received matches specific requirements becomes critical. This is where JSON Schema comes in.
What is JSON Schema?
JSON Schema is a vocabulary that allows you to annotate and validate JSON documents. It provides a human- and machine-readable documentation format and a clear contract for the data required by your application.
Why use Draft-07?
While several versions of JSON Schema exist, Draft-07 is currently one of the most widely supported versions in the developer ecosystem. It provides robust tools for defining:
- Required Fields: Ensure critical data is always present.
- Value Constrains: Define minimum/maximum lengths for strings or ranges for numbers.
- Type Safety: Enforce that a field must be an array, object, or specific primitive.
Example Schema Example
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"username": { "type": "string", "minLength": 3 },
"age": { "type": "integer", "minimum": 18 }
},
"required": ["username"]
}
Automated Generation
Defining schemas by hand is tedious. JSON Machine allows you to build your structure visually and click a single button to generate a perfect Draft-07 JSON Schema instantly.
Start building your schema: Open the Schema Generator.