Verwenden TOML Arrays und Array von Tabellen
TOML supports Arrays von primitives und Arrays von Tabellen. Lernen der syntax für inline Arrays, multi-Zeile Arrays, und [[table]] Arrays für structured Daten.
- 1
TOML arrays: inline ([1, 2, 3]) or multi-line (one element per line with trailing comma). Array of tables uses [[table]] — each occurrence appends a new element to the array. This is useful for lists of structured objects (e.g., [[servers]] with name, host, port).
- 2 TOML-Konverter →
Analysieren the TOML file and convert to JSON to verify array structures. Inline arrays become JSON arrays; [[table]] becomes an array of objects. The conversion makes the structure explicit and easy to inspect.
- 3 JSON-Formatierer →
Formatieren the converted JSON to see the array structure clearly. Arrays of tables become arrays of objects — verify the nesting and element count. This is useful for debugging TOML parsing issues.
- 4 toml-convert → json-format
Use the TOML-to-JSON workflow to parse, convert, and format in one step. This validates the TOML syntax and shows the resulting structure.
- 5
TOML array syntax: inline = [1, 2, 3], multi-line = [ 1, 2, 3 ], array of tables = [[product]] name = "A" [[product]] name = "B". Mixed-type arrays are allowed in TOML 1.0 but discouraged. Use arrays of tables for lists of configuration objects (servers, endpoints, features).
Häufige Fragen
- Can TOML arrays contain mixed types?
- TOML 1.0 allows mixed-type arrays: [1, "two", true]. However, this is discouraged — it makes parsing and validation harder. Use homogeneous arrays (all strings, all integers, all tables) for clarity and type safety.
- How do array of tables differ from inline arrays of tables?
- [[table]] creates an array of tables by appending each occurrence. You can also write inline: products = [{name = "A", price = 1}, {name = "B", price = 2}]. The [[table]] form is preferred for readability with many fields; inline is fine for short entries.