Skip to main content
The examples keyword provides an array of sample JSON values that demonstrate valid instances for a schema. These examples help developers understand how to use the schema in practice.

Syntax

The value of examples must be an array. There are no restrictions on the values within the array.

Purpose

The examples keyword is a metadata annotation that:
  • Provides sample JSON values associated with a schema
  • Illustrates typical or valid usage patterns
  • Helps generate documentation and API explorers
  • Can be used by tools to generate test data or mock responses
  • Has no effect on validation (it is purely informational)
  • Should contain values that are valid against the schema (recommended)

Behavior

When multiple occurrences of the examples keyword are applicable to a single sub-instance, implementations must provide a flat array of all values rather than an array of arrays. Implementations may use the value of the default keyword, if present, as an additional example. If examples is absent, default may still be used as an example.

Examples

Basic String Examples

Multiple examples show the variety of valid email formats.

Numeric Examples

Examples demonstrate typical price values including edge cases like very low prices.

Object Examples

Object examples show complete valid instances, including optional fields (the third example omits age).

Array Examples

Array examples demonstrate different valid configurations, including the minimum case.

Enum with Examples

Examples show the most commonly used enum values.

Complex Nested Object

Complex examples show realistic, complete data structures.

API Request Body

API examples show realistic request payloads that can be used in documentation.

Date and Time Examples

Date-time examples show various timezone representations.

Pattern Examples

Examples clarify the expected pattern format.

Using Default as an Example

The default value (20) can be used as an additional example by implementations.

Best Practices

Provide Multiple Examples

Show different valid cases, including edge cases:

Ensure Examples Are Valid

All examples should validate against the schema:

Show Real-World Values

Use realistic data rather than placeholders: