Skip to main content
The default keyword specifies a default JSON value that can be used when an instance value is not provided. It is commonly used in configuration schemas, form generation, and API documentation.

Syntax

The value of default can be of any type, including null. There are no restrictions on the value.

Purpose

The default keyword is a metadata annotation that:
  • Supplies a default value when no value is provided
  • Helps tools generate forms with pre-filled values
  • Documents the recommended or typical value for a field
  • Can be used by implementations to fill in missing values
  • Has no effect on validation (it is purely informational)
  • Should be a valid value against the associated schema (recommended)

Behavior

When multiple occurrences of the default keyword are applicable to a single sub-instance, implementations should remove duplicates. Implementations may use the default value as an additional example for documentation purposes.

Examples

Basic Default Values

The default port is 8080, which will be used if no port is specified.

String Default

Defaults to “development” environment when not specified.

Boolean Default

Logging is enabled by default.

Object with Default Values

Each property has its own default value, providing a complete default configuration.

Array Default

Defaults to allowing localhost origin.

Null Default

Defaults to null when no middle name is provided.

Configuration Schema

A complete configuration schema with sensible defaults for all settings.

Pagination Parameters

API pagination with sensible defaults for common use cases.

Theme Configuration

UI theme settings with reasonable defaults.

Feature Flags

Feature flags with safe defaults.

Retry Configuration

Retry policy with standard exponential backoff defaults.

Search Options

Search configuration with user-friendly defaults.

Best Practices

Use Valid Defaults

Ensure default values validate against the schema:

Choose Safe Defaults

Select defaults that are safe for production use:

Document Default Behavior

Combine default with description to explain the default choice: