Advanced · 9 min read
Syntax validation ensures JSON is parseable. JSON Schema goes further — it defines the expected structure, data types, required fields, and value constraints. It's the standard for API contracts, configuration validation, and data quality assurance.
What is JSON Schema?
JSON Schema is a vocabulary that lets you annotate and validate JSON documents. A schema describes what properties an object should have, what types values should be, and what constraints apply (min/max length, patterns, enums).
Basic Schema Example
For this data:
{"name": "John", "age": 30, "email": "john@example.com"}
The schema would be:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"required": ["name", "age", "email"],
"properties": {
"name": { "type": "string", "minLength": 1 },
"age": { "type": "integer", "minimum": 0 },
"email": { "type": "string", "format": "email" }
}
}
Common Schema Keywords
- type: string, number, integer, boolean, array, object, null
- required: Array of mandatory property names
- properties: Schema for each object property
- items: Schema for array elements
- minimum/maximum: Numeric constraints
- minLength/maxLength: String length constraints
- pattern: Regular expression for string validation
- enum: Allowed values list
Use Cases
- API documentation: Define request/response contracts in OpenAPI specs
- Data validation: Validate user input before processing
- Configuration: Ensure config files have required settings
- Testing: Verify API responses match expected structure
- Data migration: Validate transformed data meets target schema
Generate Schemas with AI
Our JSON viewer includes an AI Schema Builder. Describe your data structure in plain English, and the AI generates a valid JSON Schema definition you can use immediately.
Syntax vs Schema Validation
Always run syntax validation first with our JSON validator, then apply schema validation for structural checks. Both layers together ensure data quality.