Data types in toml allow you to define the type of a key and value pairs.
Toml data types
In Toml documents, value data must support the following types
- a String
- an Integer
- a Float
- a boolean
- date and time types(Offset Local date, times)
- an array
- an inline-table
toml value can not support the following types
- Binary data
- Infinity and NAN
value strings accept basic strings, multiple line strings, literals, and multiple line literals. values of strings can be represented in double-quotes as follows,
Multiple lines of strings accept as values, Multiline strings are enclosed in three quotations as follows statement=""" I am statement with multi-line strings """"
Literal values are enclosed in single quotes as follows
multi-line literal values are enclosed by three single quotes as follows
lines=''' this is multiple lines literals example'''
TOML Integer types
values in documents accept positive and negative values
key1=+45 # positive number value key2=-20 # negative number value
Big integers are expressed with an underscore as follows key3=300_000
values can also accept hexadecimal, octal and binary numbers
key5=0xDFA1 # prefix 0X for hex decimal numbers key6=0o746 # prefix 0o for octal numbers key6=0b1001 # prefix 0b for binary numbers
TOML Float types
float numbers contain integers and decimal numbers separated by a dot(.)
TOML Boolean types
Boolean is true and false in lower cases accepted as values.
TOML Date types
The following are supported date formats, Date must be as per RFC 3339
OffsetDate Time Local Date Time Local Date Local Time
offsetdatetime-key=2020-02-20T06:10:20Z # offset Date time offsetdatetime-key1=2020-02-20 06:10:20Z # offset Date time - T is replaced with spaces also localdatetime-key=2020-02-20 06:10:20 # local Date time date-key=2020-02-20 # Date type time-key=06:10:20 # Time type
TOML Array type
Like any programming language, This also provides arrays, arrays are used to group the elements referred to with a single variable name. Syntax
- Array values are enclosed with square brackets
- Double quotes are not required
- spaces are not considered
- each value in an Array-Values is separated by a comma symbol.
- value contains the same types - strings, numbers, etc.. or of mixed types- (string and numbers)
- values contain multiple lines with a line break or enter
TOML Array of strings/numbers Example
Array values contain the same type of data i.e. strings.
numbers=[1,2,3,4] # array of numbers weekends=["SATURDAY","SUNDAY"] # array of strings floatarray=[1.0,3.5] # array of floats mixed-array-1=[1,"one"] # array of mixed type array-multiple-lines=[ 7,9,0 ]
nested array in toml examples
a nested array is an array of arrays, each element in an array contains an array of values.
nested-array-key=[[2,3],[5,6]] # nested array of numbers nested-array-key1=[ [12,3], ["URL1","URL2"] ] # nested array of mixed types
Table Data type
One of the important types is the type that is a representation of HashTable or properties objects in another programming language. The table stores the collection of keys and values under a one name
[table-name] key="value" #line break
Table type rules
- The first line of the table is enclosed in a square bracket
- The last line must be EOF or specify the next table.
- data in the table is unordered
- All the data type rules are applied to table data
- spaces are ignored
- Tables without data is valid
- Duplicate tables are not allowed
[my-table] id=1 name="Frank"
Inline Table type
This is another way of expressing data in table format examples
Inline tables data is enclosed in curly braces
All the data placed in a single line
Newline inside braces are invalid