Blog post
JSON Schema Validation: A Complete Guide with Examples
Learn JSON Schema validation from scratch — Draft 7 syntax, required fields, type constraints, pattern matching, array validation, and validation with AJV in JavaScript.
Shashank Jain
Author


Article
What is JSON Schema?
JSON Schema is a vocabulary for validating the structure and content of JSON documents. It lets you define required fields, value types, min/max constraints, string patterns, and more — then validate any JSON against those rules.
Basic Schema Example
{
"type": "object",
"required": ["name", "age"],
"properties": {
"name": { "type": "string", "minLength": 1 },
"age": { "type": "integer", "minimum": 0, "maximum": 150 },
"email": { "type": "string", "format": "email" }
},
"additionalProperties": false
}Type Keywords
| Keyword | Validates |
|---|---|
| string | String values |
| number | Integer or float |
| integer | Integer only |
| boolean | true / false |
| null | null |
| array | Array |
| object | Object |
Array Validation
{
"type": "array",
"items": { "type": "string" },
"minItems": 1,
"maxItems": 10,
"uniqueItems": true
}Validate with AJV in JavaScript
import Ajv from 'ajv';
const ajv = new Ajv();
const schema = {
type: 'object',
required: ['name'],
properties: { name: { type: 'string' } }
};
const validate = ajv.compile(schema);
const valid = validate({ name: 'Alice' });
if (!valid) console.log(validate.errors);Test your JSON against a schema with the free JSON Schema Validator at jsondecode.com.
Keep reading
Recent blogs

Jun 14, 2026
JSON in C#: System.Text.Json and Newtonsoft Complete Guide
Serialize and deserialize JSON in C# using System.Text.Json and Newtonsoft.Json with practical examples.

Jun 14, 2026
JSON to Markdown Table: Convert JSON Arrays Instantly
Convert JSON arrays to Markdown tables in JavaScript, Python, and with the free online tool.

Jun 14, 2026
JSON in TypeScript: Type-Safe Parsing and Validation
Stop using any for JSON in TypeScript — use Zod, type guards, and generics for fully type-safe parsing.