TOML (.toml)
Background
-
- MIME type: application/toml
- Configuration file format.
- Designed to be easy to read and write by humans.
- Associates keys to values.
- Maps unambiguously to a hash table.
- Plain text format.
- Uses UTF-8 character encoding.
Import & Export
- Import["file.toml"] returns a representation of a TOML file as an Association.
- Import["file","TOML"] returns a representation of a file as a TOML file.
- Import["file.toml",elem] returns the specified data representation of a TOML file.
- Import["file",{"TOML",elem}] returns the specified data representation of a file.
- Export["file.toml",expr] creates a TOML file from expr.
- See the following reference pages for full general information:
-
Import, Export import from or export to a file CloudImport, CloudExport import from or export to a cloud object ImportString, ExportString import from or export to a string ImportByteArray, ExportByteArray import from or export to a byte array
Import Elements
- General Import elements:
-
"Elements" list of elements and options available in this file "Summary" summary of the file "Rules" list of rules for all available elements - Data representation elements:
-
"Data" data as an association - The TOML format exports elements of an association or a list.
- TOML treats an association as a list of sections. The keys specify the section names; the values specify the elements of a section as associations.
Export Options
- Export options include:
-
"AllowLiteralStrings" True whether to use double quotes "AllowMultiLineStrings" True whether to allow multiline strings "AllowRealTabsInStrings" True whether to allow tabular characters in strings "AllowUnicodeStrings" True whether to allow Unicode strings "ExpressionFormattingFunction" Automatic how expressions not supported by TOML are converted to strings "ForceMultilineArrays" False whether to write each array element in a separate line "IndentArrayElements" True whether to indent array elements "IndentSubTables" True whether to indent subtables "QuoteDatesAndTimes" False whether to quote dates and times "RelaxedFloatPrecision" False whether to allow lower the precision of floating point numbers "TerseKeyValuePair" False whether to use terse representation of key-value pairs - "ExpressionFormattingFunction" can be set to the following values:
-
Automatic default conversion to string form any form supported by Format such as InputForm f arbitrary function that converts an expression to a string
Examples
open all close allBasic Examples (2)
Scope (1)
Import Elements (2)
"Data" (1)
Export Options (11)
"AllowLiteralStrings" (1)
"AllowMultiLineStrings" (1)
By default, Export converts strings with newline characters to multiline strings:
ExportString[<|"text" -> "Line1
Line2
Line3"|>, "TOML"]Use "AllowMultilineStrings"->False to disable this conversion:
ExportString[<|"text" -> "Line1
Line2
Line3"|>, "TOML", "AllowMultiLineStrings" -> False]"AllowRealTabsInStrings" (1)
"AllowUnicodeStrings" (1)
By default, Export uses UTF-8 character encoding:
ExportString[<|"text" -> "⊕"|>, "TOML"]ToString["⊕", CharacterEncoding -> "UTF8"]Use "AllowUnicodeStrings"->False to store each non-ASCII character as escaped Unicode numbers:
ExportString[<|"text" -> "⊕"|>, "TOML", "AllowUnicodeStrings" -> False]BaseForm[ToCharacterCode["⊕", "Unicode"], 16]"ExpressionFormattingFunction" (1)
By default, Export uses different conversions to string depending on type of expression:
ExportString[<|"image" -> RandomImage[], "quantity" -> Quantity[100, "Kilometers"/"Hours"] |>, "TOML"]Use "ExpressionFormattingFunction"->InputForm to get string versions of expressions suitable for input to the Wolfram Language:
ExportString[<|"image" -> RandomImage[], "quantity" -> Quantity[100, "Kilometers"/"Hours"] |>, "TOML", "ExpressionFormattingFunction" -> InputForm]//ShortUse a function that converts expressions to strings:
ExportString[<|"image" -> RandomImage[], "quantity" -> Quantity[100, "Kilometers"/"Hours"] |>, "TOML", "ExpressionFormattingFunction" -> SpokenString]"ForceMultilineArrays" (1)
By default, Export writes elements of short arrays in a single line:
ExportString[<|"a" -> Range[5]|>, "TOML"]Use "ForceMultilineArrays"->True to write each array element in a separate line:
ExportString[<|"a" -> Range[5]|>, "TOML", "ForceMultilineArrays" -> True]"IndentArrayElements" (1)
By default, Export indents array elements:
ExportString[<|"a" -> Range[5]|>, "TOML", "ForceMultilineArrays" -> True]Use "IndentArrayElements"->False to disable this indentation:
ExportString[<|"a" -> Range[5]|>, "TOML", "ForceMultilineArrays" -> True, "IndentArrayElements" -> False]"IndentSubtables" (1)
By default, Export indents subtables:
ExportString[<|"table" -> <|"a" -> "b", "subtable" -> <|"c" -> "d"|>|>|>, "TOML"]Use "IndentSubTables"->False to disable this indentation:
ExportString[<|"table" -> <|"a" -> "b", "subtable" -> <|"c" -> "d"|>|>|>, "TOML", "IndentSubTables" -> False]"QuoteDatesAndTimes" (1)
By default, Export does not add quotes around dates and times:
ExportString[<|"now" -> Now|>, "TOML"]Use "QuoteDatesAndTimes"->True to add quotes around dates and times:
ExportString[<|"now" -> Now|>, "TOML", "QuoteDatesAndTimes" -> True]"RelaxedFloatPrecision" (1)
By default, Export uses full precision of floating-point numbers:
ExportString[<|"pi" -> Pi, "a" -> 2.3|>, "TOML"]Use "RelaxedFloatPrecision"->True to lower the precision of floating-point numbers:
ExportString[<|"pi" -> Pi, "a" -> 2.3|>, "TOML", "RelaxedFloatPrecision" -> True]"TerseKeyValuePair" (1)
By default, Export adds spaces around "=" character for key-value pairs:
ExportString[<|"a" -> 1, "b" -> 2|>, "TOML"]Use "TerseKeyValuePair"->True to create terse representation of key-value pairs:
ExportString[<|"a" -> 1, "b" -> 2|>, "TOML", "TerseKeyValuePair" -> True]Related Guides
History
Introduced in 2026 (15.0)