Skip to content
configkit

Redefining a table in TOML

TOML lets you define each key and each table once. ConfigKit reports a second definition as 'trying to redefine an already defined table or value'. Other parsers may call it a duplicate key.

Cause 1: the same key twice

name = "a"
name = "b"

The error points at line 2. TOML does not let the second value win. Delete one of them.

Cause 2: the same table header twice

[server]
port = 1

[server]
host = "x"

This often happens when two people add settings to the same file. Merge both blocks under one [server] header.

[server]
port = 1
host = "x"

Cause 3: extending an inline table

An inline table is closed when its brace closes. Adding to it later, with a header or a dotted key, is a redefinition.

server = { port = 1 }
server.host = "x"

Put every key inside the braces, or switch to a [server] table.

What is allowed

A sub-table is a different table, so it can follow its parent:

[server]
port = 1

[server.tls]
enabled = true

To repeat a table on purpose, for a list of servers or dependencies, use double brackets. Each [[servers]] adds one item to an array.

[[servers]]
name = "a"

[[servers]]
name = "b"

The JSON is {"servers": [{"name": "a"}, {"name": "b"}]}.

Paste the file into the TOML validator to find the second definition, or into TOML to JSON to see the structure the tables build.