hank-builds.com

JSON Schema Validation - Validate JSON Structure

What is JSON Schema?

JSON Schema is a vocabulary for annotating and validating JSON documents. It lets you define the expected structure, types, and constraints for your data — then automatically check whether a JSON document conforms to those rules. It's widely used for API validation, configuration files, and data interchange formats.

Basic Schema Structure

A JSON Schema is itself a JSON object. The simplest schema specifies a type:

{ "type": "string" }Value must be a string
{ "type": "number" }Value must be a number
{ "type": "boolean" }Value must be true or false
{ "type": "object" }Value must be an object
{ "type": "array" }Value must be an array
{ "type": "null" }Value must be null

Object Validation

Objects are the most common type to validate. Key keywords:

propertiesDefine schemas for specific keys
requiredArray of keys that must be present
additionalPropertiesWhether extra keys are allowed (default: true)
minProperties / maxPropertiesLimit the number of keys

Example: { "type": "object", "required": ["name"], "properties": { "name": { "type": "string" } } }

Array Validation

itemsSchema that every element must match
minItems / maxItemsLimit the number of elements
uniqueItemsAll elements must be distinct

Example: { "type": "array", "items": { "type": "string" }, "minItems": 1 } — a non-empty array of strings.

String & Number Constraints

minLength / maxLengthString length limits
patternRegex pattern the string must match
formatSemantic format: date, email, uri, ipv4, etc.
minimum / maximumNumber range limits
enumValue must be one of the listed options

Formats like date, email, and uri are fully validated — an invalid email address will be flagged as an error.

Using Schema Validation

In the JSON Workbench, the schema validator appears as a collapsible card above the output area whenever you have valid JSON loaded:

  • Load sample — Click to load a sample schema that demonstrates common validation rules.
  • Paste your own — Expand the card and paste any JSON Schema into the textarea.
  • Live validation — Errors update instantly as you edit either the JSON or the schema.
  • Click errors — Click any error path to jump to that location in the tree viewer.
  • Persistent — Your schema is saved to localStorage and restored on reload.