WARNINGThis post was drafted using AI, drawing from my personal notes and online resources, and later refined by a human.
TOML - A Configuration File Format For Humans
TOML is a configuration file format designed with human-friendliness in mind. At its core, TOML is meant to be1:
- is easy to read due to obvious semantics
- maps unambiguously to a hash table
- is easy to parse into data structures in a wide variety of languages
The Power of TOML Lies in its Versatility
What makes TOML so powerful is its ability to cater to different forms of data. It supports a variety of native types such as 1:
- Key/Value Pairs.
- Arrays.
- Tables.
- Inline tables.
- Arrays of tables.
- Integers & Floats.
- Booleans.
- Dates & Times, with optional offsets.
Wide Support Across Langauges
TOML is supported in most of the most popular programming languages including C, C#, C++, Clojure, Dart, Elixir, Erlang, Go, Haskell, Java, JavaScript, Lua, Objective-C, Perl, PHP, Python, Ruby, Rust, Scala, Swift, and plenty more.
A quick look at a few libraries for python, C++ and Julia:
- tomllib is a read-only parser and serializer for Python. From Python 3.11 onwards tomlib is included in the Python Standard Library.
- tomlplusplus and toml11 are two great libraries for parsing and serializing TOML in C++17 and C++11 respectively.
- TOML.jl is a Julia standard library for parsing and writing TOML v1.0 files.
TOML vs Other Formats2
Compared to other formats like XML, .cfg, .ini, YAML, JSON, and even Python files, TOML strikes an excellent balance between verbosity, complexity, and functionality.
- XML tends to be overly verbose.
- .cfg and .ini formats often lack flexibility.
- YAML and TOML are both user-friendly and powerful.
While JSON is widely used, its lack of support for comments can be a drawback, making TOML a preferred alternative for many.
In conclusion, TOML is a robust and versatile configuration file format that meets a wide range of programming needs effectively.