TOML 05 ๐ Array of Tables vs Inline Tables
TOML has two ways to represent a list of objects: the array-of-tables syntax with double brackets [[table]], and the inline-table syntax with an array of curly-brace objects table = [{...}]. They can produce identical parsed data, but they differ in how they are written, where they can appear, and what the parser does with subsequent key-value pairs. The array-of-tables form is a header that opens a context; the inline form is a value that closes itself.
This chapter covers both forms, the structural rules that distinguish them, and the cases where one is required or preferable. It explains why an array of tables persists until the next header, why inline tables cannot span lines in TOML 1.0, and how the ordering problem with nested tables inside arrays of tables makes inline tables the safer choice for plugin configurations. The sections that follow walk through the array-of-tables syntax and its scope, the inline-table syntax and its self-containment, and the decision between them.
Key point: [[name]] appends a new table to an array and every following key-value pair belongs to that table until the next header; name = [{...}] defines the entire array as a single value that is self-contained and cannot be extended later.
Why two forms exist
The append problem. Some configuration shapes are lists of repeated structures: multiple input plugins, multiple products, multiple servers. The array-of-tables syntax is designed for this: each [[products]] header appends a new element to the products array, and the key-value pairs under it define that element . The header form makes the repetition visible and lets each element grow with its own nested tables.
The self-containment problem. An inline table is fully defined within its braces. All keys and sub-tables exist at the point of definition, and nothing can be added outside the braces . This is the property that makes inline tables safe inside arrays: points = [{x = 1, y = 2}, {x = 3, y = 4}] defines an array of two complete tables without relying on headers or indentation. The trade-off is that the inline table cannot be extended later.
The ordering problem. A nested table header inside an array-of-tables element must appear at the end of that element’s definition. Every key-value pair after a table header belongs to that table, regardless of indentation. In the Telegraf documentation, this is shown as a real bug: writing [inputs.cpu.tags] before percpu = false causes percpu to be parsed as a tag named “percpu,” not as a plugin option. The documentation recommends using inline table syntax instead: tags = {tag1 = "foo", tag2 = "bar"} can appear anywhere in the plugin definition without changing the scope .
a. Array-of-tables syntax and scope
An array of tables is written with a double-bracketed header: [[name]]. Each occurrence of the same header appends a new table to the array. The key-value pairs that follow belong to that table until another [[name]] header, a [table] header, or the end of the file .
# Two elements in the products array
[[products]]
name = "Hammer"
sku = 738594937
[[products]]
name = "Nail"
sku = 284758393
The parsed result is an array of two objects. The order is the order of appearance. A double-bracketed header with no key-value pairs is an empty table in the array .
The scope rule is the source of subtle bugs. Newlines do not end the scope of an array-of-tables element. In the official clarification, a key-value pair after the second [[song]] header belongs to the second song, not to the root table . This is why nested table headers must come last: once a nested header appears, every following pair belongs to the nested table, not to the parent array element.
b. Inline-table syntax and self-containment
An inline table is written between curly braces: { key = value, key = value }. An array of inline tables is written as name = [{...}, {...}]. The entire structure is a single value; it does not open a context for later pairs.
# Array of inline tables
points = [
{ x = 1, y = 2, z = 3 },
{ x = 7, y = 8, z = 9 },
{ x = 2, y = 4, z = 8 }
]
# Single inline table as a value
name = { first = "Tom", last = "Preston-Werner" }
In TOML 1.0, inline tables are intended to appear on a single line. No newlines are allowed between the braces unless they are valid within a value, and a trailing comma is not permitted . TOML 1.1 relaxed this: inline tables can have pairs on different lines and a terminating comma is permitted . The version your parser implements determines which form is valid.
Inline tables are fully self-contained. Keys and sub-tables cannot be added outside the braces, and an inline table cannot be used to add keys to an already-defined table . This is the opposite of the array-of-tables header, which opens a context that later pairs extend.
c. Choosing between them
The decision is driven by whether the data needs to be extended after its initial definition and whether nested tables are involved.
Use array of tables when the structure is a list of repeated sections that each have their own key-value pairs and may have nested tables, and when the file is organized as a sequence of headers. This is the form used by Telegraf plugins, Cargo dependencies (in some forms), and many application configuration files .
Use array of inline tables when the list is a compact value, when the elements do not need nested table headers, or when the elements appear inside another structure where a header would break the parent’s scope. The Telegraf documentation explicitly recommends inline tables for nested tag maps inside an array-of-tables element because they avoid the ordering trap .
The two forms can be equivalent. The TOML specification shows that the array-of-tables form and the array-of-inline-tables form produce the same data . The choice is about syntax and scope, not about the resulting data model.
Complete Example Session
# ============================================
# PART 1: ARRAY OF TABLES (HEADER FORM)
# ============================================
[[products]]
name = "Hammer"
sku = 738594937
[[products]]
name = "Nail"
sku = 284758393
# Parsed: products = [
# { name: "Hammer", sku: 738594937 },
# { name: "Nail", sku: 284758393 }
# ]
# ============================================
# PART 2: ARRAY OF INLINE TABLES (VALUE FORM)
# ============================================
points = [
{ x = 1, y = 2, z = 3 },
{ x = 7, y = 8, z = 9 }
]
# Parsed: points = [
# { x: 1, y: 2, z: 3 },
# { x: 7, y: 8, z: 9 }
# ]
# ============================================
# PART 3: NESTED TABLE ORDERING PROBLEM
# ============================================
[[inputs.cpu]]
percpu = false
totalcpu = true
[inputs.cpu.tags]
tag1 = "foo"
tag2 = "bar"
# tags must come last; percpu and totalcpu cannot follow it
# ============================================
# PART 4: INLINE TABLE AVOIDS ORDERING
# ============================================
[[inputs.cpu]]
tags = { tag1 = "foo", tag2 = "bar" }
percpu = false
totalcpu = true
# tags is a value; it does not change the scope of later keys
# ============================================
# PART 5: SELF-CONTAINMENT
# ============================================
[product]
type = { name = "Nail" }
# type.edible = false # INVALID: cannot extend inline table
The parts covered the array-of-tables form, the array-of-inline-tables form, the nested-table ordering trap, the inline-table workaround, and the self-containment restriction.
Quick Reference
Syntax Comparison
| Aspect | Array of Tables | Inline Tables |
|---|---|---|
| Syntax | [[name]] header | name = [{...}] value |
| Scope | Opens context until next header | Self-contained |
| Extendable | Yes, by subsequent pairs | No, defined entirely in braces |
| Nested tables | Headers after parent | Must be inline within braces |
| Multi-line (1.0) | Yes | No |
| Multi-line (1.1) | Yes | Yes |
| Trailing comma (1.0) | N/A | No |
| Trailing comma (1.1) | N/A | Yes |
When to Use Which
| Scenario | Recommendation |
|---|---|
| Repeated plugin/service blocks | Array of tables |
| Compact list of objects | Inline tables |
| Nested tag maps inside an array element | Inline table |
| Elements that need nested table headers | Array of tables |
| Value inside another structure | Inline table |
Scope Rules
| Form | After Definition |
|---|---|
[[name]] | Following pairs belong to that element |
name = [{...}] | Following pairs belong to the parent table |
[name.child] inside array element | Following pairs belong to child, not the array element |
Best Practices
โ Do This:
# Use array of tables for repeated sections
[[inputs.file]]
files = ["/var/log/app.log"] # โ
# Use inline tables for nested maps inside array elements
[[inputs.cpu]]
tags = { env = "prod", team = "ops" }
percpu = false # โ
# Keep inline tables on one line (TOML 1.0)
point = { x = 1, y = 2 } # โ
โ Don’t Do This:
# Nested header before remaining parent keys
[[inputs.cpu]]
[inputs.cpu.tags]
tag1 = "foo"
percpu = false # becomes tag "percpu" # โ
# Extend an inline table
type = { name = "Nail" }
# type.edible = false # โ
# Multi-line inline table in TOML 1.0
point = {
x = 1 # โ (1.0)
}
Common Pitfalls
| Pitfall | Why It Happens | Fix |
|---|---|---|
| Key becomes nested tag | Header appeared before remaining keys | Put nested header last or use inline |
| Cannot add to inline table | Self-contained by definition | Use standard table or array of tables |
| Inline table parse error on newline | TOML 1.0 forbids newlines in braces | Keep on one line or use 1.1 parser |
| Array element key at root | Newline ended array element | Use header form or check scope |
| Double brackets with space | [ [name] ] invalid | Use adjacent [[name]] |
Real-World Examples
1. Array of tables for plugins
[[inputs.file]]
files = ["/var/log/a.log"]
[[inputs.file]]
files = ["/var/log/b.log"]
2. Array of inline tables for points
points = [{ x = 1, y = 2 }, { x = 3, y = 4 }]
3. Inline tags inside array element
[[inputs.cpu]]
tags = { env = "prod" }
percpu = false
4. Nested header at end of element
[[inputs.cpu]]
percpu = false
[inputs.cpu.tags]
env = "prod"
5. Single inline table value
name = { first = "Tom", last = "Preston-Werner" }
6. Array of tables as equivalent to inline
[[products]]
name = "Hammer"
7. Equivalent inline form
products = [{ name = "Hammer" }]
8. Inline table in array with multiple keys
servers = [{ host = "a", port = 80 }, { host = "b", port = 443 }]
9. Nested inline table
animal = { type = { name = "pug" } }
10. Dotted key in inline table
animal = { type.name = "pug" }
Visual
Scope Comparison
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ARRAY OF TABLES โ
โ โ
โ [[products]] โโโ opens element 1 โ
โ name = "Hammer" โโโ belongs to element 1 โ
โ sku = 738594937 โโโ belongs to element 1 โ
โ โ
โ [[products]] โโโ opens element 2 โ
โ name = "Nail" โโโ belongs to element 2 โ
โ โ
โ Scope persists until next header โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ INLINE TABLES โ
โ โ
โ products = [ โ
โ { name = "Hammer", sku = 738594937 }, โ
โ { name = "Nail", sku = 284758393 } โ
โ ] โ
โ โ
โ Each {} is complete and closed โ
โ Nothing after the ] belongs to the array โ
โ No headers, no scope extension โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
The Ordering Trap
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ NESTED HEADER BEFORE PARENT KEYS โ
โ โ
โ [[inputs.cpu]] โ
โ [inputs.cpu.tags] โโโ opens nested table โ
โ tag1 = "foo" โ
โ percpu = false โโโ now belongs to tags! โ
โ โ
โ Parsed: tags = { tag1 = "foo", percpu = false } โ
โ percpu is a tag, not a plugin option โ
โ โ
โ FIX: put [inputs.cpu.tags] last โ
โ or use tags = { tag1 = "foo" } โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Equivalence
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ SAME DATA, TWO SYNTAXES โ
โ โ
โ [[products]] products = [ โ
โ name = "Hammer" { name = "Hammer" }, โ
โ sku = 1 { name = "Nail" } โ
โ [[products]] ] โ
โ name = "Nail" โ
โ sku = 2 โ
โ โ
โ Parsed result: identical array of objects โ
โ Choice is about syntax and scope, not data model โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Summary
| Item | Value |
|---|---|
| Array of tables syntax | [[name]] header |
| Array of inline tables syntax | name = [{...}, {...}] |
| Array-of-tables scope | Until next header |
| Inline table scope | Self-contained; no extension |
| Nested header position | Must be last in array element |
| Inline table multi-line (1.0) | Forbidden |
| Inline table multi-line (1.1) | Permitted |
| Equivalence | Both produce same data |
Key takeaways:
[[name]]appends and opens a scope. Every following key-value pair belongs to that array element until the next header. This is why nested table headers inside an element must come last, or the remaining keys become part of the nested table .name = [{...}]is a value, not a scope. The array and its elements are fully defined within the brackets and braces. Nothing after the closing bracket belongs to the array, and nothing inside the braces can be extended later .- The two forms can produce identical data. The array-of-tables form and the array-of-inline-tables form are equivalent at the data level; the choice is about syntax and scope .
- Inline tables avoid the ordering trap. Inside an array-of-tables element, a nested tag map written as
tags = { ... }can appear anywhere without changing what later keys belong to. A[parent.tags]header changes the scope for everything after it . - Version matters for inline-table syntax. TOML 1.0 forbids newlines and trailing commas in inline tables; TOML 1.1 permits both. Check the parser’s supported version before using multi-line inline tables .
Remember: The array-of-tables header is a context switch; the inline table is a closed value. The header form is for repeated sections that grow and may contain nested tables. The inline form is for compact lists of complete objects, especially when they appear inside another structure where a header would break the parent’s scope. When a key ends up in the wrong place inside an array-of-tables element, the cause is almost always a nested header that appeared too early. Move the header to the end, or replace it with an inline table.
Stop using slow, ad-bloated tool sites! ๐คฎ
๐ Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
โ
Finance (Mortgage, Interest, Inflation)
โ
Tech (Base64, JSON, Dev Suite, IP)
โ
Health (BMI, BMR, TDEE)
โ
Productivity (Timer, Workspace, QR)
โก๏ธ Fast & Private
๐ No data leaves your device
๐ 100% Free
๐ Use it now: https://tools.kandz.me
๐ Bookmark itโyouโll need it later!