REFERENSI CEPAT TOML
Tabel, string, angka, tanggal, array
Sintaks
Aturan Dasar
| key = value | Pasangan kunci-nilai (satu per baris) |
| # | Komentar (sampai akhir baris) |
| Case sensitive | Kunci dan nilai membedakan huruf besar-kecil |
| UTF-8 | File harus berupa UTF-8 yang valid |
| No null | TOML tidak memiliki tipe null |
Contoh Minimal
title = "My App"
debug = true
port = 8080
String
Jenis String
| "basic" | String dasar (mendukung escape) |
| 'literal' | String literal (tanpa escape) |
| """multi""" | String dasar multi-baris |
| '''multi''' | String literal multi-baris |
Contoh
basic = "Hello\nWorld"
literal = 'C:\Users\path'
multi = """
Line one
Line two"""
Urutan Escape
| \n \t \r | Baris baru, tab, carriage return |
| \\ | Backslash |
| \uXXXX | Unicode (4 digit hex) |
| \UXXXXXXXX | Unicode (8 digit hex) |
Angka dan Boolean
Tipe Numerik
| 42 | Integer |
| 1_000_000 | Integer dengan garis bawah |
| 0xff / 0o77 / 0b11 | Hex, oktal, biner |
| 3.14 | Float |
| 5e+22 / 1e-2 | Notasi ilmiah |
| inf / nan | Nilai float spesial |
| true / false | Boolean (hanya huruf kecil) |
Contoh
count = 42
price = 19.99
hex_color = 0xFF5733
enabled = true
Tanggal
Tipe Tanggal dan Waktu
| 2026-03-26T10:30:00Z | Tanggal-waktu dengan offset (UTC) |
| 2026-03-26T10:30:00-05:00 | Tanggal-waktu dengan offset (EST) |
| 2026-03-26T10:30:00 | Tanggal-waktu lokal (tanpa zona waktu) |
| 2026-03-26 | Tanggal lokal |
| 10:30:00 | Waktu lokal |
Contoh
created = 2026-03-26T10:30:00Z
birthday = 1990-05-15
alarm = 07:00:00
Tabel
Sintaks Tabel
[server]
host = "localhost"
port = 8080
[server.ssl]
enabled = true
cert = "/path/to/cert.pem"
Array Tabel
[[users]]
name = "Alice"
role = "admin"
[[users]]
name = "Bob"
role = "user"
Aturan
| [name] | Header tabel standar |
| [a.b.c] | Kunci bertitik — tabel bersarang |
| [[name]] | Array tabel |
| No redefine | Tidak bisa mendefinisikan tabel yang sama dua kali |
Array
Sintaks Array
colors = ["red", "green", "blue"]
numbers = [1, 2, 3]
Array Multi-baris
hosts = [
"alpha.example.com",
"beta.example.com",
]
Koma trailing diperbolehkan dalam array TOML
Aturan
| Same type | Semua elemen harus bertipe sama |
| Trailing comma | Diperbolehkan setelah elemen terakhir |
| Newlines | Array bisa mencakup beberapa baris |
Tabel Inline
Sintaks Tabel Inline
point = { x = 1, y = 2 }
user = { name = "Alice", admin = true }
Aturan
| Single line | Harus ada dalam satu baris |
| No trailing comma | Koma trailing tidak diperbolehkan |
| No newlines | Tidak bisa mencakup beberapa baris |
| No adding keys | Tidak bisa menambah kunci ke tabel inline setelahnya |
Inline vs Standard
# Inline — ringkas, satu baris
db = { host = "localhost", port = 5432 }
# Standard — mudah dibaca, bisa diperluas
[db]
host = "localhost"
port = 5432
Pola Umum
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
| taplo | Toolkit TOML — formatter dan linter |
| No null | Hilangkan kunci daripada mengatur null |
| No anchors | Tidak seperti YAML, tidak ada sistem referensi/alias |
| Strict | Tidak ada kunci duplikat, tidak ada array tipe campuran |