HeoLab
ToolsBlogAboutContact
HeoLab

Free developer tools with AI enhancement. Built for developers who ship.

Tools

  • JSON Formatter
  • JWT Decoder
  • Base64 Encoder
  • Timestamp Converter
  • Regex Tester
  • All Tools →

Resources

  • Blog
  • What is JSON?
  • JWT Deep Dive
  • Base64 Explained

Company

  • About
  • Contact
  • Privacy Policy
  • Terms of Service

© 2026 HeoLab. All rights reserved.

Tools work in your browser. Zero data retention.

HomeBlogJSON Schema Validation: A Complete Guide
Table of Contents▾
  • Table of Contents
  • What is JSON Schema?
  • Basic Structure
  • Data Types
  • Validation Keywords
  • Nested Objects and Arrays
  • Using JSON Schema in Node.js
tutorials#json#json-schema#validation

JSON Schema Validation: A Complete Guide

Learn how to define, validate, and document your JSON data structures using JSON Schema — the standard for API contracts.

Trong Ngo
February 22, 2026
2 min read

Table of Contents

  • What is JSON Schema?
  • Basic Structure
  • Data Types
  • Validation Keywords
  • Nested Objects and Arrays
  • Using JSON Schema in Node.js

What is JSON Schema?

JSON Schema is a vocabulary that allows you to annotate and validate JSON documents. It acts as a contract between your API and its consumers, ensuring data always matches the expected shape.

Basic Structure

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "required": ["name", "email"],
  "properties": {
    "name": { "type": "string", "minLength": 1 },
    "email": { "type": "string", "format": "email" },
    "age": { "type": "integer", "minimum": 0 }
  }
}

Data Types

TypeExample
string"hello"
number3.14
integer42
booleantrue
array[1, 2, 3]
object{"a": 1}
nullnull

Validation Keywords

  • minLength / maxLength — string length constraints
  • minimum / maximum — number range
  • pattern — regex for strings
  • enum — allowed values
  • required — mandatory keys

Nested Objects and Arrays

{
  "type": "object",
  "properties": {
    "tags": { "type": "array", "items": { "type": "string" } },
    "address": { "type": "object", "properties": { "city": { "type": "string" } } }
  }
}

Using JSON Schema in Node.js

import Ajv from "ajv";
import addFormats from "ajv-formats";

const ajv = new Ajv();
addFormats(ajv);

const schema = {
  type: "object",
  required: ["email"],
  properties: { email: { type: "string", format: "email" } }
};
const validate = ajv.compile(schema);
const valid = validate({ email: "test@example.com" });
if (!valid) console.log(validate.errors);

Try These Tools

JSON Formatter & Validator

Format, validate, and beautify JSON data instantly. Detect errors with precise line numbers.

Related Articles

Using Regex for Form Validation: Patterns and Pitfalls

2 min read

10 Regex Patterns Every Developer Should Know

1 min read

ISO 8601 Date Format: The Standard Every Developer Should Know

1 min read

Back to Blog

Table of Contents

  • Table of Contents
  • What is JSON Schema?
  • Basic Structure
  • Data Types
  • Validation Keywords
  • Nested Objects and Arrays
  • Using JSON Schema in Node.js

Related Articles

Using Regex for Form Validation: Patterns and Pitfalls

2 min read

10 Regex Patterns Every Developer Should Know

1 min read

ISO 8601 Date Format: The Standard Every Developer Should Know

1 min read