JSON Schema Patterns — 30 Common Validation Patterns with Examples
A comprehensive reference table of 30 JSON Schema validation patterns organized by category, with syntax examples, use cases, and community engagement data from StackOverflow and the npm ecosystem.
By Michael Lip · Updated April 2026
Methodology
Patterns were identified by analyzing the top 25 JSON Schema questions on StackOverflow (sorted by votes, total 429K+ views on the top question alone) via the StackExchange API v2.3. Validator ecosystem data was sourced from the npm registry for ajv (v8.18.0, 357 versions, created 2015). Each pattern was categorized, annotated with the relevant JSON Schema draft, and paired with a minimal working example. Community engagement scores reflect real StackOverflow view counts as of April 2026.
| # | Pattern | Category | Keyword(s) | Example Syntax | SO Views |
|---|---|---|---|---|---|
| 1 | Required Properties | Object | required | {"required": ["name", "email"]} | 105K |
| 2 | String Type | Primitive | type | {"type": "string"} | -- |
| 3 | Enum Values | Primitive | enum | {"enum": ["draft", "published", "archived"]} | 231K |
| 4 | Nullable String | Primitive | type (array) | {"type": ["string", "null"]} | 206K |
| 5 | String Format — Email | String | format | {"type": "string", "format": "email"} | -- |
| 6 | String Format — UUID | String | format | {"type": "string", "format": "uuid"} | 151K |
| 7 | String Pattern (regex) | String | pattern | {"type": "string", "pattern": "^[A-Z]{2}-\\d{4}$"} | -- |
| 8 | String Min/Max Length | String | minLength, maxLength | {"type": "string", "minLength": 1, "maxLength": 255} | -- |
| 9 | Integer Range | Numeric | minimum, maximum | {"type": "integer", "minimum": 0, "maximum": 100} | -- |
| 10 | Exclusive Range | Numeric | exclusiveMinimum | {"type": "number", "exclusiveMinimum": 0} | -- |
| 11 | Array of Strings | Array | items | {"type": "array", "items": {"type": "string"}} | -- |
| 12 | Array of Objects | Array | items | {"type": "array", "items": {"type": "object", "properties": {...}}} | 154K |
| 13 | Array Min/Max Items | Array | minItems, maxItems | {"type": "array", "minItems": 1, "maxItems": 10} | 67K |
| 14 | Unique Items | Array | uniqueItems | {"type": "array", "uniqueItems": true} | 43K |
| 15 | Array of Enums | Array | items + enum | {"type": "array", "items": {"enum": ["a", "b", "c"]}} | 231K |
| 16 | Nested Object | Object | properties | {"properties": {"address": {"type": "object", "properties": {...}}}} | -- |
| 17 | No Additional Properties | Object | additionalProperties | {"additionalProperties": false} | 61K |
| 18 | Pattern Properties | Object | patternProperties | {"patternProperties": {"^x-": {"type": "string"}}} | 52K |
| 19 | Dynamic Keys (Map) | Object | additionalProperties | {"additionalProperties": {"type": "integer"}} | 29K |
| 20 | allOf (Schema Composition) | Composition | allOf | {"allOf": [{"$ref": "#/defs/base"}, {"required": ["id"]}]} | 58K |
| 21 | anyOf (Union Type) | Composition | anyOf | {"anyOf": [{"type": "string"}, {"type": "integer"}]} | -- |
| 22 | oneOf (Discriminated Union) | Composition | oneOf | {"oneOf": [{"properties": {"type": {"const": "email"}}}, ...]} | 135K |
| 23 | $ref (Schema Reference) | Composition | $ref | {"$ref": "#/$defs/Address"} | -- |
| 24 | Conditional — if/then/else | Conditional | if, then, else | {"if": {"properties": {"type": {"const": "business"}}}, "then": {"required": ["tax_id"]}} | -- |
| 25 | Property Dependencies | Conditional | dependentRequired | {"dependentRequired": {"credit_card": ["billing_address"]}} | -- |
| 26 | Const Value | Primitive | const | {"const": "v2"} | -- |
| 27 | Default Value | Annotation | default | {"type": "string", "default": "active"} | -- |
| 28 | Schema from JSON (Generation) | Tooling | -- | Use tools like quicktype, json-schema-generator | 430K |
| 29 | Require At Least One Of | Conditional | anyOf + required | {"anyOf": [{"required": ["email"]}, {"required": ["phone"]}]} | 50K |
| 30 | Require All Properties | Object | required (all keys) | {"required": ["a","b","c"], "properties": {"a":{}, "b":{}, "c":{}}} | 35K |
Validator Ecosystem
The most widely used JSON Schema validator in the JavaScript ecosystem is ajv (Another JSON Schema Validator), currently at version 8.18.0 with 357 published versions on npm. First created on May 29, 2015, ajv supports JSON Schema drafts 2019-09 and 2020-12, generates optimized validation code at compile time, and provides an extensible plugin architecture for custom keywords and formats. The ajv-formats plugin adds support for common string formats like email, uuid, uri, date-time, and ipv4/ipv6.
Community Engagement
JSON Schema is one of the most actively discussed data validation topics on StackOverflow. The top question alone ("Tool to generate JSON schema from JSON data") has accumulated 429,824 views and a score of 274. Nullable types (206K views), enum arrays (231K views), and array-of-objects definitions (154K views) consistently rank among the most viewed questions, indicating these patterns represent the most common pain points for developers adopting JSON Schema.
Frequently Asked Questions
What is the difference between required and optional properties in JSON Schema?
In JSON Schema, all properties are optional by default. The "required" keyword is an array at the object level that lists property names that must be present in the data. A property defined in "properties" but not included in "required" is optional. This distinction has over 105K views on StackOverflow, making it one of the most commonly misunderstood aspects of JSON Schema.
How do I prevent additional properties not defined in my JSON Schema?
Set "additionalProperties": false at the object level. This causes validation to fail if the data contains any properties not explicitly listed in the "properties" object. Be careful when combining this with allOf — each sub-schema evaluates additionalProperties independently, which can cause unexpected validation failures. This pattern has 61K+ views on StackOverflow.
What is the best JSON Schema validator for JavaScript?
Ajv (Another JSON Schema Validator) is the de facto standard for JavaScript. It has 357 published versions on npm, with the latest at v8.18.0. Ajv supports drafts 2019-09 and 2020-12, compiles schemas to optimized JavaScript code for fast validation, and supports custom keywords and formats via plugins. For Python, jsonschema is the equivalent standard library.
How do I validate a UUID format in JSON Schema?
Use {"type": "string", "format": "uuid"} in your schema. Note that format validation is an optional feature in the JSON Schema specification — validators like ajv require you to enable it explicitly via the ajv-formats plugin. Without the plugin, the format keyword is treated as an annotation only. This pattern has 150K+ views on StackOverflow.
What is the difference between oneOf, anyOf, and allOf in JSON Schema?
These are composition keywords. allOf requires data to be valid against ALL listed sub-schemas (logical AND) — used for combining schemas. anyOf requires validity against at least ONE sub-schema (logical OR) — used for union types. oneOf requires validity against EXACTLY ONE sub-schema (exclusive OR) — used for discriminated unions. The oneOf pattern alone has 135K views on StackOverflow due to its complexity.