TOML Cheat Sheet
TOML cheatsheet for TOML syntax, TOML data types, dotted keys, tables, arrays, datetimes, inline tables, and arrays of tables used in configuration files.
Comment
A comment starts with # and continues to the end of the line.
# comment
key = "value" # inline comment
# file metadata
title = "example" # stored as a string
Key-Value Pair
A key/value pair assigns a value to a key using =; the key, equals sign, and value appear on the same line.
key = "value"
number = 42
enabled = true
name = "service"
replicas = 3
enabled = true
Bare Key
A bare key uses unquoted characters.
bare_key = "value"
snake_case = 1
kebab-case = 2
port = 8080
log_level = "info"
feature-flag = true
Quoted Key
A quoted key is a string used as a key name.
"key with spaces" = "value"
'key.with.dots' = 1
"" = "empty quoted key"
"127.0.0.1" = "loopback"
"character encoding" = "utf-8"
"" = "empty-key"
Dotted Key
A dotted key is a sequence of keys joined by dots, creating nested tables implicitly.
parent.child = "value"
site."example.com" = true
name = "item"
physical.color = "orange"
physical.shape = "round"
site."example.com" = true
Redefining a Key
Defining the same key more than once in the same document is invalid.
key = "first"
key = "second" # invalid: redefinition
name = "one"
name = "two" # invalid
Basic String
A basic string is enclosed in double quotes and supports escape sequences.
str = "text"
escaped = "quote: \" backslash: \\ newline: \n tab: \t"
unicode = "pi: \u03C0"
path = "C:\\tmp\\file.txt"
message = "Line1\nLine2"
unicode = "symbol: \u2603"
Multi-line Basic String
A multi-line basic string is enclosed in triple double quotes and can contain newlines.
str = """multi
line
string"""
banner = """
first line
second line
third line"""
Multi-line Basic String Line-Ending Backslash
A line-ending backslash in a multi-line basic string trims the newline and following whitespace up to the next non-whitespace character.
str = """
first line \
second line \
third"""
text = """
The quick brown \
fox jumps over \
the lazy dog."""
Literal String
A literal string is enclosed in single quotes and does not process escape sequences.
winpath = 'C:\Users\name\templates'
regex = '<\i\c*\s*>'
pattern = '^[a-z]+\.[a-z]+$'
raw = 'backslashes are literal here: \'
Multi-line Literal String
A multi-line literal string is enclosed in triple single quotes and preserves content as written.
str = '''multi
line
literal'''
block = '''
first newline trimmed
indentation preserved
#! symbols preserved
'''
Integer (Decimal)
An integer is a whole number written in decimal; a leading + or - may be used.
int1 = +42
int2 = 0
int3 = -21
workers = 16
offset = -3
max_retries = +5
Integer Underscores
Underscores may appear between digits in numeric values.
int = 5_349_221
bytes = 1_073_741_824
Integer Bases
Non-negative integers may be written in hexadecimal (0x), octal (0o), or binary (0b) forms.
hex = 0xDEADBEEF
oct = 0o755
bin = 0b1101_0110
mask = 0xff00ff00
perm = 0o644
flags = 0b1010_0001
Float
A float can include a fractional part and/or an exponent part; underscores may be used between digits.
flt1 = 3.1415
flt2 = -5e6
flt3 = 6.626E-34
flt4 = 224_617.445_991_228
ratio = 0.75
rate = 1e06
constant = 6.626e-34
Special Float Values
Special float values are written in lowercase and include infinities and NaN.
sf1 = inf
sf2 = +inf
sf3 = -inf
sf4 = nan
sf5 = +nan
sf6 = -nan
upper_bound = +inf
invalid_result = nan
Boolean
A boolean is either true or false (lowercase).
enabled = true
disabled = false
cache = true
dry_run = false
Offset Date-Time
An offset date-time includes date, time, and timezone offset (RFC 3339).
odt = 1979-05-27T07:32:00Z
odt2 = 1979-05-26T15:32:00+08:00
created_at = 2025-12-25T20:10:00Z
expires_at = 2025-12-26T01:10:00+05:00
Local Date-Time
A local date-time includes date and time but no offset.
ldt = 1979-05-27T07:32:00
ldt2 = 1979-05-27T00:32:00.999999
scheduled = 2025-12-25T23:30:00
Local Date
A local date includes only a date portion.
ld = 1979-05-27
release_date = 2025-12-25
Local Time
A local time includes only a time portion.
lt = 07:32:00
lt2 = 00:32:00.999999
quiet_hours_start = 23:00:00
Array
An array is an ordered list of values inside []; elements are separated by commas and can span multiple lines.
ints = [1, 2, 3]
strings = ["a", "b", "c"]
nested = [[1, 2], [3, 4, 5]]
multiline = [
1,
2, # comments allowed
]
ports = [8080, 8081, 9090]
hosts = ["a.example", "b.example"]
matrix = [[1, 2], [3, 4]]
Table
A table header in [] starts a table and defines where subsequent key/value pairs are stored.
[table]
key = "value"
[table.sub]
n = 1
[server]
host = "0.0.0.0"
port = 8080
[server.tls]
enabled = true
min_version = "1.2"
Table Name Rules
Table names are non-empty; invalid table headers include empty segments.
[] # invalid
[a.] # invalid
[a..b] # invalid
[.b] # invalid
[.] # invalid
[a]
b = 1
Dotted Table Header
A dotted table header defines nested tables using dot-separated name segments.
[a.b.c]
key = "value"
[database.replica.us-east]
host = "db-replica-1"
port = 5432
Inline Table
An inline table is a table written on one line using {} with comma-separated key/value pairs.
point = { x = 1, y = 2 }
nested = { a = { b = { c = 1 } } }
owner = { name = "ops", id = 7 }
limits = { cpu = 2, mem_mb = 1024 }
Array of Tables
An array of tables uses [[name]] to append a new table element to an array under name.
[[products]]
name = "item"
sku = 123
[[products]]
name = "item2"
sku = 456
[[service.endpoints]]
name = "public"
port = 443
[[service.endpoints]]
name = "internal"
port = 8443