在瀏覽器中格式化、驗證和轉換TOML ↔ JSON。資料不會傳送到任何伺服器。
| 類型 | 範例 | 備註 |
|---|---|---|
| String (basic) | name = "Alice" | Supports \n, \t, \uXXXX escapes |
| String (literal) | path = 'C:\Users\Alice' | No escape processing — use for regex, paths |
| Multi-line string | desc = \"\"\" Line 1 Line 2\"\"\"`` | Opening newline trimmed |
| Integer | count = 42 hex = 0xFF bin = 0b1010 | Underscores allowed: 1_000_000 |
| Float | pi = 3.14159 sci = 5e22 inf = inf | nan also valid |
| Boolean | debug = true verbose = false | Always lowercase |
| Offset Date-Time | created = 1979-05-27T07:32:00Z | RFC 3339 / ISO 8601 |
| Local Date | date = 2024-01-15 | No time, no timezone |
| Array | tags = ["rust", "config"] | Mixed types allowed; multi-line OK |
| Inline Table | point = {x = 1, y = 2} | Must be on a single line |
| Table | [server] host = 'localhost' | Maps to nested object |
| Array of Tables | [[users]] name = 'Alice' | Creates an array of objects |
| 功能 | TOML | JSON | YAML |
|---|---|---|---|
| Comments | ✓ | ✗ | ✓ |
| Trailing commas | N/A | ✗ | N/A |
| Native dates | ✓ | ✗ | ✓ |
| Multi-line strings | ✓ | ✗ (escape \n) | ✓ |
| Implicit type coercion | ✗ | ✗ | ✓ (risky) |
| Human readability | High | Medium | High |
| Machine readability | High | High | Medium |
| Use case | Config files | APIs / data exchange | Config / automation |
TOML(Tom's Obvious, Minimal Language)是一種配置檔案格式,由於語義明顯而易於閱讀。它明確地映射到雜湊表,設計為YAML和JSON的配置檔案替代方案。TOML由Rust的Cargo、Python的Poetry和許多其他工具使用。
與JSON不同,TOML支援注解、多行字串,並具有原生日期/時間類型。與YAML不同,TOML具有顯式、明確的語法 — 沒有令人驚訝的隱式類型轉換或縮排陷阱。TOML通常用於配置檔案,而JSON用於資料交換API。
TOML表用[table.name]語法定義,映射到巢狀物件。表陣列使用[[array.name]](雙括號)建立物件陣列。內嵌表使用{key = value}語法進行緊湊表示。表支援任意巢狀以實現層次配置。
TOML支援:String(基本和字面/原始)、Integer(十進位、十六進位0x、八進位0o、二進位0b)、Float(包括inf和nan)、Boolean(true/false)、Offset Date-Time(RFC 3339)、Local Date-Time、Local Date、Local Time、Array(允許混合類型)和Table/Inline Table。