# TOML Quick Reference

*Tables, strings, numbers, dates, arrays*

> Source: TOML Specification (toml.io) · MIT

## Syntax

### Basic Rules

| Command | Description |
|---------|-------------|
| `key = value` | Key-value pair (one per line) |
| `#` | Comment (to end of line) |
| `Case sensitive` | Keys and values are case-sensitive |
| `UTF-8` | Files must be valid UTF-8 |
| `No null` | TOML has no null type |

### Minimal Example

```
title = "My App"
debug = true
port = 8080
```

## Strings

### String Types

| Command | Description |
|---------|-------------|
| `"basic"` | Basic string (supports escapes) |
| `'literal'` | Literal string (no escapes) |
| `"""multi"""` | Multi-line basic string |
| `'''multi'''` | Multi-line literal string |

### Examples

```
basic = "Hello\nWorld"
literal = 'C:\Users\path'
multi = """
Line one
Line two"""
```

### Escape Sequences

| Command | Description |
|---------|-------------|
| `\n  \t  \r` | Newline, tab, carriage return |
| `\\` | Backslash |
| `\uXXXX` | Unicode (4-digit hex) |
| `\UXXXXXXXX` | Unicode (8-digit hex) |

## Numbers & Booleans

### Numeric Types

| Command | Description |
|---------|-------------|
| `42` | Integer |
| `1_000_000` | Integer with underscores |
| `0xff / 0o77 / 0b11` | Hex, octal, binary |
| `3.14` | Float |
| `5e+22 / 1e-2` | Scientific notation |
| `inf / nan` | Special float values |
| `true / false` | Boolean (lowercase only) |

### Examples

```
count = 42
price = 19.99
hex_color = 0xFF5733
enabled = true
```

## Dates

### Date & Time Types

| Command | Description |
|---------|-------------|
| `2026-03-26T10:30:00Z` | Offset date-time (UTC) |
| `2026-03-26T10:30:00-05:00` | Offset date-time (EST) |
| `2026-03-26T10:30:00` | Local date-time (no timezone) |
| `2026-03-26` | Local date |
| `10:30:00` | Local time |

### Examples

```
created = 2026-03-26T10:30:00Z
birthday = 1990-05-15
alarm = 07:00:00
```

## Tables

### Table Syntax

```
[server]
host = "localhost"
port = 8080

[server.ssl]
enabled = true
cert = "/path/to/cert.pem"
```

### Array of Tables

```
[[users]]
name = "Alice"
role = "admin"

[[users]]
name = "Bob"
role = "user"
```

### Rules

| Command | Description |
|---------|-------------|
| `[name]` | Standard table header |
| `[a.b.c]` | Dotted key — nested table |
| `[[name]]` | Array of tables |
| `No redefine` | Cannot define same table twice |

## Arrays

### Array Syntax

```
colors = ["red", "green", "blue"]
numbers = [1, 2, 3]
```

### Multi-line Array

```
hosts = [
  "alpha.example.com",
  "beta.example.com",
]
```

*Trailing comma is allowed in TOML arrays*

### Rules

| Command | Description |
|---------|-------------|
| `Same type` | All elements must be the same type |
| `Trailing comma` | Allowed after last element |
| `Newlines` | Arrays can span multiple lines |

## Inline Tables

### Inline Table Syntax

```
point = { x = 1, y = 2 }
user = { name = "Alice", admin = true }
```

### Rules

| Command | Description |
|---------|-------------|
| `Single line` | Must appear on one line |
| `No trailing comma` | Trailing comma not allowed |
| `No newlines` | Cannot span multiple lines |
| `No adding keys` | Cannot add keys to inline table later |

### Inline vs Standard

```
# Inline — compact, one-liners
db = { host = "localhost", port = 5432 }
# Standard — readable, extendable
[db]
host = "localhost"
port = 5432
```

## Common Patterns

### pyproject.toml

```
[project]
name = "myapp"
version = "1.0.0"
dependencies = ["flask>=3.0"]
```

### Cargo.toml

```
[package]
name = "myapp"
version = "0.1.0"
edition = "2021"
```

### Tips

| Command | Description |
|---------|-------------|
| `taplo` | TOML toolkit — formatter and linter |
| `No null` | Omit the key instead of setting null |
| `No anchors` | Unlike YAML, no reference/alias system |
| `Strict` | No duplicate keys, no mixed-type arrays |
