Skip to content

Proposal: Extended Table Syntax with Context or Profile Prefixes #1069

@cheungxiongwei

Description

@cheungxiongwei

Proposal: Extended Table Syntax with Context or Profile Prefixes

Summary

I would like to propose an extended table syntax for TOML that allows contextual or environment-specific sections, using a colon (:) to express inheritance or specialization.

Motivation

In many configuration scenarios (e.g., application environments like development, test, production), it is common to define a base configuration and override only a few fields for each environment.
Currently, TOML does not have a direct way to express “derived” or “contextual” tables, which leads to redundant configuration blocks or requires additional logic in the parser.

Proposed Syntax

Example:

[database]
host = "localhost"
port = 3306
username = "admin"
password = "123456"

[development:database]
debug = true

[test:database]
host = "test-db.example.com"  # override host
debug = false

Semantics

  • The base table [database] defines default fields.
  • The prefixed tables [development:database], [test:database], etc. represent derived or context-specific configurations.
  • When parsed, they can conceptually “extend” the base [database] table, overriding or adding keys.
  • A parser or tool could choose to interpret this as a hierarchical configuration, e.g.:
{
  "database": {
    "host": "localhost",
    "port": 3306,
    "username": "admin",
    "password": "123456"
  },
  "development": {
    "database": {
      "host": "localhost",
      "port": 3306,
      "username": "admin",
      "password": "123456",
      "debug": true
    }
  },
  "test": {
    "database": {
      "host": "test-db.example.com",
      "port": 3306,
      "username": "admin",
      "password": "123456",
      "debug": false
    }
  }
}

Benefits

  • Reduces duplication in environment-based configuration files.
  • Keeps TOML syntax clean and readable.
  • Enables consistent hierarchical configuration management.

Alternatives

  • Using separate files per environment (e.g., config.dev.toml, config.test.toml).
  • Using table arrays or dotted keys (which are less intuitive for inheritance).

Discussion

The colon syntax could be discussed further — alternative separators like /, . or @ may also be considered.
Backward compatibility is maintained since : is currently not allowed in bare keys, so this would not conflict with existing TOML syntax.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions