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

May 22, 2026
JSONPath Guide: Query JSON Data Like SQL (with Examples)
Learn JSONPath syntax to query JSON data — basic expressions, wildcards, filters, recursive descent, and array slices. Includes JavaScript and Python examples.

May 22, 2026
How to Convert JSON to TypeScript Interfaces Automatically
Learn how to convert JSON to TypeScript interfaces — manually, with tools, and with AI. Includes nested objects, arrays, optional fields, and Zod schema generation.

May 22, 2026
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.