JSON Schema Cheat Sheet

Every JSON Schema keyword, validation rule, and format value in one place. Type constraints, combining schemas, $ref patterns, and a complete example — all in quick-reference tables.

JSONTech TeamMarch 10, 20257 min read

Type Keywords

KeywordApplies ToDescriptionExample
typeAnyRestricts the value to a specific type"type": "string"
enumAnyValue must be one of the listed values"enum": ["draft", "published"]
constAnyValue must equal this exact value"const": "active"
defaultAnyDefault value (not enforced, informational)"default": 0
titleAnyShort label for documentation"title": "User Name"
descriptionAnyLonger description for documentation"description": "The user's full name"
examplesAnyExample values for documentation"examples": ["Alice", "Bob"]

Valid type values: string, number, integer, boolean, object, array, null.

String Validations

KeywordTypeExample ValueDescription
minLengthinteger1Minimum string length (inclusive)
maxLengthinteger255Maximum string length (inclusive)
patternregex"^[A-Z]{2}\\d{4}$"Must match this regular expression
formatstring"email"Semantic format hint (see format table below)
enumarray["low", "medium", "high"]Value must be one of these strings
contentMediaTypestring"application/json"MIME type of encoded string content
contentEncodingstring"base64"Encoding of the string (e.g., base64)

Number Validations

KeywordTypeExample ValueDescription
minimumnumber0Value must be >= this (inclusive)
maximumnumber100Value must be <= this (inclusive)
exclusiveMinimumnumber0Value must be > this (exclusive)
exclusiveMaximumnumber100Value must be < this (exclusive)
multipleOfnumber5Value must be divisible by this

Use "type": "integer" to restrict to whole numbers. "type": "number" allows decimals.

Object Validations

KeywordTypeDescriptionExample
propertiesobjectDefines schemas for known properties"properties": {"name": {"type": "string"}}
requiredarrayList of properties that must be present"required": ["name", "email"]
additionalPropertiesboolean / schemaControls extra properties beyond those in properties"additionalProperties": false
minPropertiesintegerMinimum number of properties"minProperties": 1
maxPropertiesintegerMaximum number of properties"maxProperties": 10
patternPropertiesobjectSchema for properties matching a regex pattern"patternProperties": {"^x-": {"type": "string"}}
propertyNamesschemaSchema that all property names must match"propertyNames": {"pattern": "^[a-z]"}
dependentRequiredobjectIf property A exists, property B is required"dependentRequired": {"card": ["cvv"]}

Array Validations

KeywordTypeDescriptionExample
itemsschemaSchema that all array items must match"items": {"type": "string"}
prefixItemsarray of schemasSchema for each positional item (tuple validation)"prefixItems": [{"type": "string"}, {"type": "number"}]
minItemsintegerMinimum number of items"minItems": 1
maxItemsintegerMaximum number of items"maxItems": 50
uniqueItemsbooleanAll items must be unique"uniqueItems": true
containsschemaAt least one item must match this schema"contains": {"type": "number"}
minContainsintegerMinimum items matching contains"minContains": 2
maxContainsintegerMaximum items matching contains"maxContains": 5

Combining Schemas

KeywordLogicDescriptionExample
allOfANDMust match all of the listed schemas"allOf": [{"type": "string"}, {"minLength": 1}]
anyOfORMust match at least one of the listed schemas"anyOf": [{"type": "string"}, {"type": "number"}]
oneOfXORMust match exactly one of the listed schemas"oneOf": [{"minimum": 0}, {"maximum": -1}]
notNOTMust not match the given schema"not": {"type": "null"}
if / then / elseConditionalApply different schemas based on a condition"if": {"properties": {"type": {"const": "business"}}}, "then": {"required": ["taxId"]}

Format Values

Common values for the format keyword. Validation depends on the implementation — some treat these as annotations only.

FormatDescriptionExample Value
date-timeISO 8601 date-time"2025-03-10T14:30:00Z"
dateISO 8601 date"2025-03-10"
timeISO 8601 time"14:30:00Z"
durationISO 8601 duration"P3Y6M4DT12H30M5S"
emailEmail address (RFC 5321)"user@example.com"
idn-emailInternationalized email"user@例え.jp"
uriFull URI (RFC 3986)"https://example.com/path"
uri-referenceURI or relative reference"/path/to/resource"
uuidUUID (RFC 4122)"550e8400-e29b-41d4-a716-446655440000"
ipv4IPv4 address"192.168.1.1"
ipv6IPv6 address"::1"
hostnameInternet hostname (RFC 1123)"api.example.com"
regexECMA-262 regular expression"^[a-z]+$"
json-pointerJSON Pointer (RFC 6901)"/foo/bar/0"

$ref — Reusing Schemas

Use $ref to reference shared definitions and avoid repetition:

{
  "$defs": {
    "address": {
      "type": "object",
      "properties": {
        "street": { "type": "string" },
        "city": { "type": "string" },
        "zip": { "type": "string", "pattern": "^\\d{5}$" }
      },
      "required": ["street", "city", "zip"]
    }
  },
  "type": "object",
  "properties": {
    "billing": { "$ref": "#/$defs/address" },
    "shipping": { "$ref": "#/$defs/address" }
  }
}
$ref PatternPoints To
#/$defs/nameLocal definition in the same schema
other.jsonRoot of an external schema file
other.json#/$defs/nameDefinition inside an external file
https://example.com/schema.jsonRemote schema by URL

Complete Example Schema

A full schema for a user registration API request:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://api.example.com/schemas/user",
  "title": "User Registration",
  "description": "Schema for creating a new user account",
  "type": "object",
  "properties": {
    "username": {
      "type": "string",
      "minLength": 3,
      "maxLength": 30,
      "pattern": "^[a-zA-Z0-9_]+$"
    },
    "email": {
      "type": "string",
      "format": "email"
    },
    "password": {
      "type": "string",
      "minLength": 8,
      "maxLength": 128
    },
    "age": {
      "type": "integer",
      "minimum": 13,
      "maximum": 150
    },
    "role": {
      "type": "string",
      "enum": ["user", "admin", "moderator"],
      "default": "user"
    },
    "tags": {
      "type": "array",
      "items": { "type": "string", "maxLength": 50 },
      "maxItems": 10,
      "uniqueItems": true
    },
    "address": { "$ref": "#/$defs/address" }
  },
  "required": ["username", "email", "password"],
  "additionalProperties": false,
  "$defs": {
    "address": {
      "type": "object",
      "properties": {
        "street": { "type": "string" },
        "city": { "type": "string" },
        "country": { "type": "string", "minLength": 2, "maxLength": 2 },
        "zip": { "type": "string" }
      },
      "required": ["street", "city", "country"]
    }
  }
}

Generate schemas automatically: Paste any JSON payload into our JSON Schema Generator to instantly create a valid JSON Schema — then customize from there.

Related Tools