jsondecode.com logo

HomeChevronBlogChevronJSON Schema Validation: A Complete Guide with Examples

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.

author

Shashank Jain

Author

22/05/20260 minutes 41 seconds read
JSON Schema Validation: A Complete Guide with ExamplesJSON Schema Validation: A Complete Guide with Examples

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

KeywordValidates
stringString values
numberInteger or float
integerInteger only
booleantrue / false
nullnull
arrayArray
objectObject

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

View all

If jsondecode.com saved you time, share it with your team

Free forever. No ads. No sign-up. Help other developers find it.