toml-foolery 2.1.0

Populates any given D struct with data read from a TOML string, and vice-versa.

To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

Main Repo   ·    Mirror   ·    Dub Package Registry   ·    Documentation


toml-foolery logo

Toml-foolery is a library for the D programming language which simplifies encoding and decoding of TOML-formatted data. There are no intermediate types that couple your code to this library — Toml-foolery parses TOML data directly into any struct, and structs can be converted into TOML.

Toml-foolery v2.1.0 is compatible with TOML v1.0.0.


The parseToml template function decodes TOML code into a D data structure. It may optionally receive a pre-made instance of that struct as its second argument.

The tomlify function encodes D data structure as TOML code. It accepts any struct and returns a string containing TOML data.

Note that toml-foolery doesn't do any file I/O.

Each field of the given struct becomes a TOML key-value pair, where the key is the name of the field in D. This can be customized by applying the @TomlName attribute to a field. The string passed to this attribute is the key name to look for when decoding TOML data, and the key name to write when encoding the struct into TOML.


import std.datetime;
import std.file;
import std.stdio;

import toml_foolery;

void main()
    string tomlSource = `
        name = "Rincewind"
        dateOfBirth = 2032-10-23
        profession = "Wizard"

        name = "Unseen University"
        city = "Ankh-Morpork"

        name = "Luggage"
        species = "Arca vulgaris"
        profession = "Thief"

    Person person = parseToml!Person(tomlSource);

    writeln("And back into TOML:");

struct Person
    enum Profession

    struct Animal
        string name;
        string species;
        Profession profession;

    struct Establishment
        string name;
        string city;

    string name;
    Date dateOfBirth;
    Profession profession;

    Establishment almaMater;

    Animal[] pets;


Person("Rincewind", 2032-Oct-23, Wizard, Establishment("Unseen University", "Ankh-Morpork"), [Animal("Luggage", "Arca vulgaris", Thief)])

And back into TOML:

name = "Rincewind"
dateOfBirth = 2032-10-23
profession = "Wizard"

name = "Unseen University"
city = "Ankh-Morpork"

name = "Luggage"
species = "Arca vulgaris"
profession = "Thief"

TOML–D type correspondence

Type of fieldResulting TOML type
string, wstring, dstring, char, wchar, dcharString
byte, short, int, long, ubyte, ushort, uint, ulong¹Integer
float, double, realFloating point
std.datetime.systime.SysTimeOffset Date-Time Date-Time³ Date Time³
Array of the above typesArray of the corresponding TOML type
Array of structsArray of tables
Associative arrayTable

¹ The TOML specification requires Integers to be in the range [long.min, long.max], so toml-foolery will throw a TomlTypeException if the input contains an integer outside that range.

² Parsing is case-sensitive.

³ The TOML specification expects at least millisecond precision for local date-times and local times, but the D standard library's corresponding data structures are precise only to the second. Any fractional-second precision will be lost upon parsing.


  • If the parsed TOML data contains keys that don't match any fields in the given struct, toml-foolery will ignore those keys.
  • If a destination field is a static array, but the corresponding array in the TOML code is too big to fit, additional entries will be ignored. Dynamic arrays will be resized as needed.
  • The TOML specification allows mixed-type arrays, but toml-foolery does not yet support them.
  • Toml-foolery does not support classes or pointers.
  • Line-separators are preserved when decoding multiline strings.
  • Toml-foolery can parse all features of TOML, but when encoding data into TOML, some formats will not be created:
    • Inline tables (Regular []-syntax is always used)
    • Dotted keys (same as above)
    • Literal strings (regular "strings" used instead)
    • Multiline strings (same as above)
  • Andrej Petrović
datefmt, pegged
2.1.0 2021-Dec-13
2.0.0 2021-Nov-04
1.0.1 2021-Jun-19
1.0.0 2020-Apr-21
~master 2021-Dec-13
Show all 5 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 61 downloads total

Short URL: