Data Validation

What is JSON Schema?

5 Min Read• Published 2026

Introduction to Schema Validation

JSON Schema is a declarative vocabulary that allows you to annotate and validate JSON documents. It provides a structured format to specify the allowed properties, data types, value boundaries, and required keys in your JSON dataset.

A Simple Schema Example

Here is a basic schema describing a user profile dataset:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "User",
  "type": "object",
  "properties": {
    "id": {
      "type": "integer"
    },
    "username": {
      "type": "string",
      "minLength": 3
    },
    "email": {
      "type": "string",
      "format": "email"
    }
  },
  "required": ["id", "username"]
}

Why Use Schema Assertions?

  • API Security: Validates incoming HTTP payloads before querying the database, blocking malicious or malformed parameter structures.
  • Autogenerated Docs: Provides a single source of truth that client libraries or documentation tools can render.
  • Type Safety: Infers exact schema shapes to compile static TypeScript interfaces.