Original Research

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
1Required PropertiesObjectrequired{"required": ["name", "email"]}105K
2String TypePrimitivetype{"type": "string"}--
3Enum ValuesPrimitiveenum{"enum": ["draft", "published", "archived"]}231K
4Nullable StringPrimitivetype (array){"type": ["string", "null"]}206K
5String Format — EmailStringformat{"type": "string", "format": "email"}--
6String Format — UUIDStringformat{"type": "string", "format": "uuid"}151K
7String Pattern (regex)Stringpattern{"type": "string", "pattern": "^[A-Z]{2}-\\d{4}$"}--
8String Min/Max LengthStringminLength, maxLength{"type": "string", "minLength": 1, "maxLength": 255}--
9Integer RangeNumericminimum, maximum{"type": "integer", "minimum": 0, "maximum": 100}--
10Exclusive RangeNumericexclusiveMinimum{"type": "number", "exclusiveMinimum": 0}--
11Array of StringsArrayitems{"type": "array", "items": {"type": "string"}}--
12Array of ObjectsArrayitems{"type": "array", "items": {"type": "object", "properties": {...}}}154K
13Array Min/Max ItemsArrayminItems, maxItems{"type": "array", "minItems": 1, "maxItems": 10}67K
14Unique ItemsArrayuniqueItems{"type": "array", "uniqueItems": true}43K
15Array of EnumsArrayitems + enum{"type": "array", "items": {"enum": ["a", "b", "c"]}}231K
16Nested ObjectObjectproperties{"properties": {"address": {"type": "object", "properties": {...}}}}--
17No Additional PropertiesObjectadditionalProperties{"additionalProperties": false}61K
18Pattern PropertiesObjectpatternProperties{"patternProperties": {"^x-": {"type": "string"}}}52K
19Dynamic Keys (Map)ObjectadditionalProperties{"additionalProperties": {"type": "integer"}}29K
20allOf (Schema Composition)CompositionallOf{"allOf": [{"$ref": "#/defs/base"}, {"required": ["id"]}]}58K
21anyOf (Union Type)CompositionanyOf{"anyOf": [{"type": "string"}, {"type": "integer"}]}--
22oneOf (Discriminated Union)CompositiononeOf{"oneOf": [{"properties": {"type": {"const": "email"}}}, ...]}135K
23$ref (Schema Reference)Composition$ref{"$ref": "#/$defs/Address"}--
24Conditional — if/then/elseConditionalif, then, else{"if": {"properties": {"type": {"const": "business"}}}, "then": {"required": ["tax_id"]}}--
25Property DependenciesConditionaldependentRequired{"dependentRequired": {"credit_card": ["billing_address"]}}--
26Const ValuePrimitiveconst{"const": "v2"}--
27Default ValueAnnotationdefault{"type": "string", "default": "active"}--
28Schema from JSON (Generation)Tooling--Use tools like quicktype, json-schema-generator430K
29Require At Least One OfConditionalanyOf + required{"anyOf": [{"required": ["email"]}, {"required": ["phone"]}]}50K
30Require All PropertiesObjectrequired (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.