JSON Schema Examples: Required, Enum, Arrays, and Objects

If you already understand what JSON Schema is and just need working snippets, this page is the fast path. Each example is copy-paste friendly and targets a common validation pattern.

Object with required fields

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "required": ["id", "email"],
  "properties": {
    "id": { "type": "integer" },
    "email": { "type": "string", "format": "email" },
    "name": { "type": "string" }
  }
}

Enum example

{
  "type": "string",
  "enum": ["pending", "active", "disabled"]
}

Array of objects

{
  "type": "array",
  "items": {
    "type": "object",
    "required": ["sku", "qty"],
    "properties": {
      "sku": { "type": "string" },
      "qty": { "type": "integer", "minimum": 1 }
    }
  }
}

For a broader walkthrough of these keywords, see JSON Schema tutorial.

String pattern example

{
  "type": "string",
  "pattern": "^[A-Z]{3}-\d{4}$"
}

Disallow extra fields

{
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "id": { "type": "integer" },
    "name": { "type": "string" }
  }
}

Nullable field example

{
  "type": "object",
  "properties": {
    "deletedAt": {
      "type": ["string", "null"],
      "format": "date-time"
    }
  }
}

Test schema examples against real JSON

Paste these snippets into Jsonic's JSON Schema Validator to validate real payloads in the browser.

Open JSON Schema Validator