đĄ Expert Insight: JSON Schema validation catches 90% of API integration bugs before they reach production. Define your expected data structure once, then validate every request/response automatically. It's like TypeScript for your JSON data!
Validate JSON Data Structure with JSON Schema
Syntax validation only tells you if JSON is parseable. But is it correct? Does it have the right fields? Are the data types what you expect? Is the email actually an email?
Our JSON Schema Validator goes beyond syntax checking. It validates your JSON data against a schema definition, ensuring your data structure, types, and constraints are exactly what your application expects. Perfect for API development, configuration validation, and data integrity checks.
Why Use JSON Schema Validation?
Catch Data Structure Errors
Syntax validation says your JSON is valid, but schema validation ensures it has the right structure. Missing required fields, wrong data types, or invalid values are caught immediately before they cause runtime errors.
API Contract Enforcement
Define what your API expects and returns. Validate requests before processing and responses before sending. Prevents breaking changes and ensures API consumers get consistent data.
Configuration File Validation
Ensure config files have all required settings with correct types. Catch configuration errors before deployment, not after your app crashes in production.
Data Integrity Checks
Validate imported data, database exports, and user submissions. Ensure data meets business rules like minimum values, string patterns, and required relationships.
đ Real Example:
Problem: API returns user data but sometimes "age" is a string "30" instead of number 30
Syntax Validation: â Valid JSON (doesn't catch the problem!)
Schema Validation: â Error: "age" must be type number (catches it!)
Result: Bug found before it crashes your app
How to Use This Tool
Step 1: Paste your JSON data in the left panel
Step 2: Define your JSON Schema in the right panel (or click "Load Example")
Step 3: Click "Validate Against Schema"
Step 4: Review results - green for valid, red with detailed errors if invalid
JSON Schema Basics
Simple Type Validation
Validate that fields are the correct type:
{
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "number"},
"active": {"type": "boolean"}
}
}
Required Fields
Specify which fields must be present:
{
"type": "object",
"properties": {
"email": {"type": "string"},
"password": {"type": "string"}
},
"required": ["email", "password"]
}
Value Constraints
Set minimum/maximum values, string lengths, and patterns:
{
"type": "object",
"properties": {
"age": {
"type": "number",
"minimum": 0,
"maximum": 150
},
"email": {
"type": "string",
"pattern": "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"
}
}
}
Advanced Schema Features
Array Validation
Validate arrays with specific item types, minimum/maximum lengths, and unique items:
{
"type": "array",
"items": {"type": "string"},
"minItems": 1,
"maxItems": 10,
"uniqueItems": true
}
This schema ensures the array contains 1-10 unique strings. Perfect for validating tags, categories, or user selections.
Nested Object Validation
Validate complex nested structures like addresses, user profiles, or configuration objects:
{
"type": "object",
"properties": {
"user": {
"type": "object",
"properties": {
"name": {"type": "string"},
"contact": {
"type": "object",
"properties": {
"email": {"type": "string"},
"phone": {"type": "string"}
},
"required": ["email"]
}
},
"required": ["name", "contact"]
}
}
}
Enum Values
Restrict values to a specific set of allowed options:
{
"type": "object",
"properties": {
"status": {
"type": "string",
"enum": ["pending", "active", "completed", "cancelled"]
},
"priority": {
"type": "number",
"enum": [1, 2, 3, 4, 5]
}
}
}
Enums are perfect for status fields, priority levels, or any field with a fixed set of valid values.
String Format Validation
JSON Schema supports built-in format validators for common patterns:
- email: Validates email addresses
- uri: Validates URLs and URIs
- date: Validates ISO 8601 dates (YYYY-MM-DD)
- date-time: Validates ISO 8601 timestamps
- ipv4/ipv6: Validates IP addresses
- uuid: Validates UUIDs
{
"type": "object",
"properties": {
"email": {"type": "string", "format": "email"},
"website": {"type": "string", "format": "uri"},
"birthdate": {"type": "string", "format": "date"},
"created": {"type": "string", "format": "date-time"}
}
}
Real-World Use Cases
API Request Validation
Validate incoming API requests before processing to prevent invalid data from entering your system. Define a schema for each endpoint:
{
"type": "object",
"properties": {
"username": {
"type": "string",
"minLength": 3,
"maxLength": 20,
"pattern": "^[a-zA-Z0-9_]+$"
},
"password": {
"type": "string",
"minLength": 8
},
"email": {
"type": "string",
"format": "email"
}
},
"required": ["username", "password", "email"],
"additionalProperties": false
}
Result: Invalid requests are rejected immediately with clear error messages, preventing database corruption and security issues.
Configuration File Validation
Ensure application config files have all required settings with correct types before deployment:
{
"type": "object",
"properties": {
"database": {
"type": "object",
"properties": {
"host": {"type": "string"},
"port": {"type": "number", "minimum": 1, "maximum": 65535},
"name": {"type": "string"}
},
"required": ["host", "port", "name"]
},
"cache": {
"type": "object",
"properties": {
"enabled": {"type": "boolean"},
"ttl": {"type": "number", "minimum": 0}
}
}
},
"required": ["database"]
}
Benefit: Catch configuration errors in CI/CD pipelines before deployment, not after your app crashes in production.
Form Data Validation
Validate user-submitted form data on both client and server side:
{
"type": "object",
"properties": {
"firstName": {"type": "string", "minLength": 1},
"lastName": {"type": "string", "minLength": 1},
"age": {"type": "number", "minimum": 18, "maximum": 120},
"terms": {"type": "boolean", "const": true}
},
"required": ["firstName", "lastName", "age", "terms"]
}
The const keyword ensures users must accept terms (value must be exactly true).
đ Case Study: E-commerce API
Problem: An e-commerce platform was receiving orders with invalid data - negative quantities, missing product IDs, invalid email addresses.
Solution: Implemented JSON Schema validation for order requests.
Schema Enforced:
- Product ID must be a valid UUID
- Quantity must be between 1 and 100
- Email must be valid format
- Shipping address must have all required fields
Result: 95% reduction in order processing errors, saving 20 hours/week of manual data cleanup!
Common Schema Patterns
User Profile Schema
{
"type": "object",
"properties": {
"id": {"type": "string", "format": "uuid"},
"username": {"type": "string", "minLength": 3, "maxLength": 20},
"email": {"type": "string", "format": "email"},
"age": {"type": "number", "minimum": 13},
"roles": {
"type": "array",
"items": {"type": "string", "enum": ["user", "admin", "moderator"]},
"uniqueItems": true
},
"createdAt": {"type": "string", "format": "date-time"}
},
"required": ["id", "username", "email"]
}
Product Schema
{
"type": "object",
"properties": {
"sku": {"type": "string", "pattern": "^[A-Z0-9-]+$"},
"name": {"type": "string", "minLength": 1, "maxLength": 200},
"price": {"type": "number", "minimum": 0, "multipleOf": 0.01},
"inStock": {"type": "boolean"},
"categories": {
"type": "array",
"items": {"type": "string"},
"minItems": 1
}
},
"required": ["sku", "name", "price", "inStock"]
}
The multipleOf: 0.01 ensures prices are valid currency amounts (2 decimal places).
API Response Schema
{
"type": "object",
"properties": {
"success": {"type": "boolean"},
"data": {"type": "object"},
"error": {
"type": "object",
"properties": {
"code": {"type": "string"},
"message": {"type": "string"}
}
},
"timestamp": {"type": "string", "format": "date-time"}
},
"required": ["success", "timestamp"],
"oneOf": [
{"required": ["data"]},
{"required": ["error"]}
]
}
The oneOf keyword ensures either data or error is present, but not both.
Best Practices
Start Simple, Add Constraints Gradually
Begin with basic type validation, then add constraints as you understand your data better. Don't try to create the perfect schema on the first attempt.
Use Descriptive Property Names
Clear property names make schemas self-documenting. Use emailAddress instead of email, createdTimestamp instead of created.
Add Descriptions
Include description fields to document what each property represents:
{
"type": "object",
"properties": {
"age": {
"type": "number",
"minimum": 0,
"maximum": 150,
"description": "User's age in years"
}
}
}
Set additionalProperties
Use "additionalProperties": false to prevent unexpected fields:
{
"type": "object",
"properties": {
"name": {"type": "string"}
},
"additionalProperties": false
}
This catches typos and prevents clients from sending extra data.
Version Your Schemas
Include a $schema property to specify which JSON Schema version you're using:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {...}
}
Troubleshooting Common Issues
Validation Passes But Data Still Causes Errors
Cause: Schema doesn't cover all business logic constraints
Solution: Add more specific constraints. For example, if a date must be in the future, add a custom validator or use formatMinimum.
Schema Too Complex to Maintain
Cause: Trying to validate everything in one schema
Solution: Break complex schemas into smaller, reusable definitions using $ref:
{
"definitions": {
"address": {
"type": "object",
"properties": {
"street": {"type": "string"},
"city": {"type": "string"}
}
}
},
"type": "object",
"properties": {
"billing": {"$ref": "#/definitions/address"},
"shipping": {"$ref": "#/definitions/address"}
}
}
Error Messages Too Technical
Cause: Default AJV error messages are developer-focused
Solution: Map error paths to user-friendly messages in your application code.
Performance Issues with Large Data
Cause: Validating huge arrays or deeply nested objects
Solution: Compile schemas once and reuse the validator. Use maxItems and maxProperties to limit data size.
Integration with Development Workflow
CI/CD Pipeline Validation
Add schema validation to your build process:
- Validate config files before deployment
- Validate API request/response examples in documentation
- Fail builds if schemas don't match actual data
API Documentation
Use JSON Schema in OpenAPI/Swagger specifications. Many tools can generate documentation from schemas automatically.
Code Generation
Generate TypeScript interfaces, validation code, or mock data from JSON Schemas using tools like json-schema-to-typescript.
Testing
Use schemas to generate test data and validate test fixtures. Ensures your tests use realistic, valid data.
Privacy and Security
Your data is completely safe with our validator:
- Client-Side Processing: All validation happens in your browser using the AJV library
- No Data Storage: We never save your JSON data or schemas
- No Server Uploads: Your data never leaves your device
- Open Source Library: AJV is a trusted, open-source validation library
- No Account Required: Use anonymously, no registration needed
Conclusion
JSON Schema validation is essential for modern API development, configuration management, and data integrity. By defining your data structure once, you can validate it everywhere - in your application, CI/CD pipeline, documentation, and tests.
Our free JSON Schema Validator makes it easy to test and refine your schemas before deploying them. Use the "Load Example" button to get started, then customize the schema for your specific needs. Whether you're building APIs, validating user input, or ensuring configuration correctness, JSON Schema catches errors before they reach production.
Start validating your JSON data structure today - no downloads, no registration, complete privacy!




