| | |

TOML 05 ๐Ÿ“„ Array of Tables vs Inline Tables

โฑ๏ธ Estimated read: 10 min | |

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

AspectArray of TablesInline Tables
Syntax[[name]] headername = [{...}] value
ScopeOpens context until next headerSelf-contained
ExtendableYes, by subsequent pairsNo, defined entirely in braces
Nested tablesHeaders after parentMust be inline within braces
Multi-line (1.0)YesNo
Multi-line (1.1)YesYes
Trailing comma (1.0)N/ANo
Trailing comma (1.1)N/AYes

When to Use Which

ScenarioRecommendation
Repeated plugin/service blocksArray of tables
Compact list of objectsInline tables
Nested tag maps inside an array elementInline table
Elements that need nested table headersArray of tables
Value inside another structureInline table

Scope Rules

FormAfter Definition
[[name]]Following pairs belong to that element
name = [{...}]Following pairs belong to the parent table
[name.child] inside array elementFollowing 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

PitfallWhy It HappensFix
Key becomes nested tagHeader appeared before remaining keysPut nested header last or use inline
Cannot add to inline tableSelf-contained by definitionUse standard table or array of tables
Inline table parse error on newlineTOML 1.0 forbids newlines in bracesKeep on one line or use 1.1 parser
Array element key at rootNewline ended array elementUse header form or check scope
Double brackets with space[ [name] ] invalidUse 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

ItemValue
Array of tables syntax[[name]] header
Array of inline tables syntaxname = [{...}, {...}]
Array-of-tables scopeUntil next header
Inline table scopeSelf-contained; no extension
Nested header positionMust be last in array element
Inline table multi-line (1.0)Forbidden
Inline table multi-line (1.1)Permitted
EquivalenceBoth 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.

Was this helpful?


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!