C.W.K.
Stream
Lesson 06 of 08 · published

Tables — Sections, Nested, Inline

~12 min · toml, tables, sections

Level 0Plaintext
0 XP0/64 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

Three ways to write structured config

Standard tables — [section]

A line that starts with [name] opens a new table. All keys after it (until the next table header) belong to that table. Names follow key syntax (bare or quoted, dotted for nested).

Nested tables — [section.subsection]

Dots in the table header create nesting. [server.database] is the database table inside the server table.

Inline tables — { key = value, ... }

Curly-brace tables fit on one line. Use them for small inline objects (a single point, a single config value) where a full [section] would feel heavy. Inline tables are self-contained — once written, they cannot be added to with later [section] headers.

Order matters less than YAML

You can write [a.b] before [a], or skip [a] entirely (it implicitly exists). The parser figures it out. The cost is that re-reading the file in source order doesn't always match the parsed structure — a small price for flexibility.

'You cannot redefine a table': once a table is opened with [server], you can't write [server] again later. Keep all of a table's keys under one header. (Sub-tables and arrays-of-tables are different — the next lesson covers those.)

Code

Standard table·toml
title = "My App"
version = "1.0"

[server]
host = "localhost"
port = 8000

[database]
url = "postgresql://localhost/pippa"
pool_size = 5
Nested tables·toml
[server]
host = "localhost"
port = 8000

[server.tls]
enabled = true
cert_file = "./certs/server.pem"

[server.tls.cipher]
list = ["AES256-GCM", "CHACHA20"]
minimum_version = "TLS1.2"
Inline tables·toml
# Same data, two styles
# Style A — standard table:
[point]
x = 0.5
y = 1.7

# Style B — inline table:
point = { x = 0.5, y = 1.7 }

# Inline tables are great inside arrays:
endpoints = [
  { name = "login",   path = "/auth/login",  rate_limit = 60 },
  { name = "signup",  path = "/auth/signup", rate_limit = 5  },
  { name = "chat",    path = "/chat",        rate_limit = 30 },
]

External links

Exercise

Take a deep YAML config with 4+ levels of nesting. Write the same data in TOML using nested-table headers ([a.b.c]). Read both. For deeply nested config, TOML's flat-but-prefixed style is often clearer than YAML's whitespace-driven indentation — you can see at a glance which subtree a value lives under.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.