TOML Syntax
TOML file contains the documents each document contains the syntax specified as per TOML supported rules. Each document or line contains key and value pairs Following is the syntax
key= “value”
key and value pair are separated by equal sign and value must be double quotes Key of type string which accepts characters/ASCII codes/numbers/dashes and underscores
Example file
# this is a sample file
following are valid keys
key="value"
test_key="value"
956="value"
key-1="value"
key = "value" #keys with spaces are allowed
"key" = "value" # quoted keys are valid
dev.db.url="localhost" # keys contains dotted symbol are allowed for grouping
Invalid keys
- value without keys are not allowed, for example, =“without key”
- duplicate keys are not allowed
value types
values accept of types string, integer, Float, Boolean, Date types, Array and tables only
TOML data key and value pair rules
- value must be enclosed in double quotes
- key and value pair declared in single line only
- spaces before or after key and value pairs are ignored
- the key is of type string and value supports limited values of different types
- new line must be followed by key and value pairs in a single line
- if the value is not declared, the default value is INVALID
How to declare comments in the toml file?
Like a programming language, It supports comments.
Comments
are usually ignored by runtime interpreters.
Comments are useful to specify the explanation of the configuration data.
Hash symbol is used for specifying comments at the starting character in the line.
\# this is comment
environment="development"
It supports single-line comments and does not supports multi-line comments
if you want to specify the multiple lines, each line is marked with the # symbol