TOML CheatSheet

Simplify your configuration file format with TOML and take your development game to the next level. Our TOML cheat sheet is designed to provide developers with a clear and concise reference guide for mastering this intuitive language. Featuring an organized and sophisticated layout, our cheat sheet covers everything from defining tables, keys, and values to advanced features such as arrays, inline tables, and more. Its concise yet comprehensive nature saves developers time and reduces errors, allowing them to build clean and elegant code with ease. Whether you're a beginner or an expert developer, our TOML cheat sheet provides an essential resource that will help you navigate the complexities of this powerful configuration file format. Elevate your development experience and streamline your workflow with our TOML cheat sheet today.


Table of Content




# Getting started for TOML


What is TOML?

TOML is abbreviated as Toms Obvious, Data format serialization language and it is a new file format. It is used for specifying data in configurations similar to YAML.

TOML is a minimal configuration file format that's easy to read due to obvious semantics.

It is used to configure the parameters and settings of various software projects. TOML files contain configuration information in key-value pairs and are meant to be more readable than .JSON files and simpler than .YAML files.

The name "TOML" is an acronym for "Tom's Obvious, Minimal Language"


TOML Advantages

  • It is human-readable for complex configuration and settings
  • Support all popular languages - GO, Java, Python, Javascript, etc.
  • Supports Comments
  • Maintainable
  • Gain more popularity than other file formats
  • Read and write capabilities
  • the content of these files looks like windows init format

TOML Disadvantages

  • Numbers like NAN and infinity are not supported
  • No support for binary data
  • Only supports a few data types, not extendable

When To Use TOML ?

  • TOML can be used in many types of projects for different purposes
  • Configuration and settings of the software applications
  • Toml file is like a normal ini file in windows that can be used to support configuration settings in different applications using multiple programming languages.
  • Spring projects, toml file used to configure environment settings for different environment profiles.
  • It provides strong typing to make it a configuration with typed values.

Syntax

TOML's syntax primarily consists of key = "value" pairs, [section names], and # comments. TOML's syntax somewhat resembles that of .INI files, but it includes a formal specification, whereas the INI file format suffers from many competing variants.

Its specification includes a list of supported data types: String, Integer, Float, Boolean, Datetime, Array, and Table.

TOML file extension

TOML document grouped in a file with extension toml, You can use any IDE or text editor to open this file.

All the popular IDE supports the toml file extension and also provides plugins to validate the toml file content

Data Rules

  • data in toml files are case sensitive
  • file supports UTF-8 encoding format only
  • Supports whitespaces, tabs, and newlines asci code

Examples

bool = false
  date = 2005-06-27T07:32:00Z
  string = "hello world"
  number = 45
  float = 3.14
  scientificNotation = 1e+12

Comments

# A single line comment example
  
  # block level comment example
  # comment line 1
  # comment line 2
  # comment line 3

Integer

intA = +41
  intB = 0
  intC = -22
  integerRange = 65

Float

floatA = 3.1687
  floatB = 5e+21
  floatC = 6.626e-32

Boolean

boolTrue = true
  boolFalse = false

Datetime

date1 = 1989-05-27T07:32:00Z
  date2 = 1989-05-26T15:32:00-07:00
  date3 = 1989-05-27T07:32:00
  date4 = 1989-05-27
  time1 = 07:32:00
  time2 = 00:32:00.999999

String

str = "Hello World"
  str1 = "I'm bestforstudy.com"
  str2 = "You can \"quote\" me."
  str3 = "Name\tJos\u00E9\nLoc\tSF."

Table

[owner]
  name = "Tom Preston-Werner"
  dob = 1979-05-27T07:32:00-08:00

Array

arrayA = [4, 5, 6]
  arrayB = ["Hello", "bestforstudy", ".com"]
  arrayC = [8003, 8004, 8005]

Friendly Array

array1 = [ "Don't mix", "different", "types" ]
  array2 = [ [ 1.2, 2.4 ], ["all", 'strings', """are the same""", '''type'''] ]
  array3 = [
    "Whitespace", "is", 
    "ignored"
  ]

# TOML Strings


Multiline String

multiLineString = """
  Hello I am bestforstudy.com
  """

Literal String

path = 'C:\Users\nodejs\templates'
  path2 = '\\User\admin$\system32'
  quoted = 'Tom "Dubs" Preston-Werner'
  regex = '<\i\c*\s*>'

MultiLine Literal String

re = '''\d{2} apps is t[wo]o many'''
  lines = '''
  Hello, I am bestforstudy.com
  '''

# TOML Tables


Basic

[name]
  cool = 1
  great = 2

Nested

[table1]
      foo = "bar"
  
  [table1.nested_table]
      baz = "bat"

Array-like


  [[comments]]
  author = "Jack"
  text = "Great Job!"
  
  [[comments]]
  author = "bestforstudy.com"
  text = "I Love it!"
  

Json Preview


  {
    "comments": [
      {
        "author": "Jack",
        "text": "Great Job!"
      },
      {
        "author": "bestforstudy.com",
        "text": "I Love It!"
      }
    ]
  }
  

Dot separated


  [dog."tater.man"]
  type = "pug"
  

Json Preview


  {
    "dog": {
      "tater.man": {
        "type": "pug"
      }
    }
  }
  

Multi-nested


  [foo.bar.baz]
  bat = "Hello bestforstudy.com"
  

Json Preview


  {
    "foo": {
      "bar": {
        "baz": {
          "bat": "Hello bestforstudy.com"
        }
      }
    }
  }
  

Ignore whitespace

[a.b.c]          # this is best practice
  [ d.e.f ]        # same as [d.e.f]
  [ g .  h  .i ]   # same as [g.h.i]
  [ j . "?" .'l' ] # same as [j."?".'l']

Inline Table

name = { first = "Jack", last = "Jack" }
  
  point = { x = 1, y = 2 }
  
  animal = { type.name = "Corgi Dog" }


Best Suggest