Basic assignment:
key = "value"
Browse / TOML Configuration File Cheatsheet
TOML Configuration File Cheatsheet
A quick reference guide to the TOML (Tom's Obvious, Minimal Language) configuration file format syntax, data types, and structure, including useful tips and examples.
Basic Syntax & Types
Key-Value Pairs
|
|
Keys can contain letters, numbers, underscores, and hyphens. |
|
Dotted keys for nesting. Equivalent to tables. |
Is same as:
|
Keys must be quoted if they contain special characters (like spaces, |
|
Keys must be unique within their table/scope. |
|
Case-sensitive. |
|
Whitespace around keys and values is ignored. |
|
Comments
Start with |
|
Comments can appear anywhere except within strings. |
Used for explanations, disabling lines, etc. |
Blank lines and comments are ignored by parsers. |
Help improve readability and documentation of your config file. |
Strings
Basic Strings: Enclosed in |
|
Multiline Basic Strings: Enclosed in |
|
Multiline Basic Strings with |
|
Literal Strings: Enclosed in |
|
Multiline Literal Strings: Enclosed in |
|
Numbers
Integers: Decimal numbers. |
|
Integers: Hexadecimal (prefix |
|
Integers: Octal (prefix |
|
Integers: Binary (prefix |
|
Floats: Standard decimal numbers with a fractional part or exponent. |
|
Floats: Special values |
|
Booleans
|
Represents the boolean true value. |
|
Represents the boolean false value. |
Case-sensitive. Must be lowercase |
|
Datetimes
Full Datetime (with timezone): |
|
Full Datetime (with timezone and fractional seconds): |
|
Local Datetime (without timezone): |
|
Local Datetime (without timezone and with fractional seconds): |
|
Local Date (without time): |
|
Local Time (without date): |
|
Local Time (with fractional seconds): |
|
Data Structures
Arrays
Arrays are enclosed in |
Elements are separated by commas. |
Whitespace is ignored. |
|
Arrays can contain elements of different types, but this is discouraged for consistency. |
|
Arrays can contain other arrays or tables (inline tables). |
|
Trailing commas are allowed. |
|
Tables
Tables (also known as sections or hash tables) are defined by a header like |
Keys below a table header belong to that table until the next table header or EOF. |
|
Table names follow the same rules as keys. |
Quoted table names are allowed for special characters or starting with digits. |
|
Nested tables are created using dotted names. |
This is equivalent to:
|
If a table or dotted key is defined implicitly (e.g., |
|
Inline Tables
Inline tables provide a more compact syntax for tables, especially useful within arrays or as values. |
Enclosed in |
Key-value pairs separated by commas. |
Must appear on a single line. |
|
Useful inside arrays. |
|
Contain key-value pairs just like standard tables, but cannot contain other standard tables or arrays of tables (but can contain inline tables). |
|
Array of Tables
Used to represent a list of tables (or records). |
Defined by a header like |
Each |
This creates an array named
|
Keys below a |
Nested arrays of tables are defined with dotted names. |
|
Cannot define an array of tables if a standard table with the same name already exists, or vice-versa. |
|
Tips & Best Practices
General Readability
Use underscores |
Use blank lines to separate logical groups of key-value pairs or tables. |
Add comments ( |
Prefer standard tables |
Limit line length for better readability. |
Structuring Your File
Conventionally, place top-level key-value pairs first, followed by standard tables, then arrays of tables. |
Group related configuration options under appropriate table headers. |
Use dotted keys ( |
Avoid mixing implicit table definitions (via dotted keys) and explicit definitions in a way that causes errors (see Table section in Page 2). |
Keep table and key names descriptive and concise. |
Data Types
Use the most specific data type possible (e.g., boolean for flags, integer for counts, datetime for timestamps). |
Avoid mixed-type arrays unless absolutely necessary; it often indicates a design issue. |
Use multiline strings |
Use literal strings |
Tooling & Validation
Always validate your TOML files using a parser or linter before deploying. |
Many programming languages have robust TOML parsing libraries. |
Editors often have syntax highlighting and basic validation for |
File Naming Convention
Use the |