Skip to content
Data & Analysis 7 min read

How to Validate JSON Against a Schema: Complete Developer Guide

Learn how JSON Schema validation works, write schemas that catch data errors, understand draft versions (4 through 2020-12), and validate any JSON against any schema in your browser.

ToolsVito Team

What JSON Schema Does

JSON Schema is a vocabulary that lets you annotate and validate JSON documents. You define the shape of valid data — required fields, types, ranges, patterns, and nested structures — and a validator checks actual JSON against those rules. If validation fails, you get detailed error messages with the exact path to each failing field. This is the foundation of API contract testing, configuration validation, and form data integrity.

A Simple Schema

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

This schema says: data must be an object, with name (non-empty string, required), email (string with email format, required), and age (integer 0–150, optional). Any JSON that violates these rules fails validation with a specific error.

Validation Keywords

  • type: The base type — string, number, integer, boolean, array, object, null.
  • properties / required: Define the shape of objects and which fields must be present.
  • enum: Restrict a value to a fixed set of options.
  • pattern: A regex that string values must match.
  • minimum / maximum: Numeric bounds. Use exclusiveMinimum for strict inequality.
  • minLength / maxLength: String length constraints.
  • minItems / maxItems / uniqueItems: Array constraints.
  • oneOf / anyOf / allOf: Logical composition of schemas — match exactly one, any, or all.
  • $ref: Reference a schema defined elsewhere in the document.

Draft Versions

JSON Schema has evolved through several drafts. Draft-04 is the most widely deployed (legacy). Draft-07 is the practical minimum for new projects. Draft 2020-12 is the latest and aligns with the JSON Schema standardization effort. Different validators support different drafts — always set $schema to declare which draft you're using and use a validator that supports it.

Reading Validation Errors

A validation error tells you (1) which constraint was violated, (2) the path to the offending field in JSON Pointer notation, and (3) the value that failed:

#/age: must be <= 150
#/email: must match format "email"
#/name: must NOT have fewer than 1 characters

JSON Pointer paths use # as the document root, / as path separator, and ~0 and ~1 for escaping ~ and / in property names.

Validate JSON Now

Use ToolsVito's JSON Schema Validator — paste your schema and data, pick a draft version, and get detailed validation results with exact error paths. All validation runs in your browser.

Try it now — free, runs in your browser

JSON Schema Validator

Validate JSON against a schema