| | |

TOML 04 ๐Ÿ“„ Data Types โ€” Strings, Integers, Floats, Booleans, Dates/Times

โฑ๏ธ Estimated read: 9 min | |

TOML’s type system is small and explicit. Every value on the right side of an assignment must be one of ten types: string, integer, float, boolean, offset date-time, local date-time, local date, local time, array, or inline table . The scalar typesโ€”strings, numbers, booleans, and the four date/time formsโ€”are the vocabulary of every configuration file, and each has rules that determine what parses and what fails. There is no implicit conversion: a quoted "42" is a string, an unquoted 42 is an integer, and the parser does not guess.

This chapter covers the scalar types and their syntax. It explains the four string forms and when each is appropriate, the integer and float formats including hexadecimal, octal, binary, and special values, the boolean literals, and the four date/time types that distinguish absolute instants from local wall-clock values. The sections that follow walk through strings, numbers, booleans, and dates/times, with the edge cases that cause parse errors.

Key point: TOML types are determined by syntax, not by content; a string is always quoted, a number is always bare, and the four date/time types are distinguished by whether they carry a timezone offset and whether they include a date, a time, or both.


Why explicit scalar types exist

The string-quoting problem. TOML strings must be quoted, which means a value that looks numeric is never accidentally numeric. version = "1.10" is a string and stays "1.10"; version = 1.10 is a float and becomes 1.1. This is the fix for the YAML version-truncation problem: the author’s intent is encoded in the syntax, not inferred by the parser .

The date/time distinction problem. TOML has four date/time types, not one. An offset date-time includes a timezone and represents an absolute instant. A local date-time has no timezone and represents a wall-clock value that cannot be converted to an instant without additional information. A local date is a day with no time. A local time is a time of day with no date . The distinction matters because a schedule that says “09:00 local time” is not the same as “09:00 UTC,” and conflating them produces bugs that only appear across timezones.

The escape problem. Basic strings support escape sequences for tabs, newlines, Unicode, and quotes; literal strings do not. A Windows path like C:\Users\name written as a basic string requires escaping every backslash. The literal form exists so that backslashes and regex patterns can be written exactly as they appear, without escape processing .


a. Strings: four forms

TOML has four string forms: basic, multi-line basic, literal, and multi-line literal. Basic strings use double quotes and process escape sequences. Literal strings use single quotes and process nothing.

# Basic string: escape sequences processed
basic = "Line one\nLine two"
escaped = "She said \"hello\""
unicode = "Jos\u00E9"

# Literal string: no escaping, backslashes literal
path = 'C:\Users\nodejs\templates'
regex = '<\i\c*\s*>'

Multi-line strings use triple delimiters. A newline immediately after the opening delimiter is trimmed. A line-ending backslash in a multi-line basic string trims the newline and all following whitespace, joining lines without introducing a space .

# Multi-line basic: newlines preserved, first newline trimmed
description = """
Line one
Line two"""

# Line-ending backslash joins lines
joined = """\
  The quick brown \
  fox jumps over \
  the lazy dog.\
  """

The multi-line literal form (triple single quotes) is the escape hatch for strings containing both quotes and backslashes, such as regex patterns or shell scripts with embedded quotes.


b. Integers and floats

Integers are whole numbers with optional sign. They support decimal, hexadecimal (0x), octal (0o), and binary (0b) prefixes. Underscores may separate digits for readability, but each underscore must be surrounded by digits .

# Decimal integers
int1 = +99
int2 = 42
int3 = 0
int4 = -17

# Prefixed integers
hex = 0xDEADBEEF
oct = 0o755
bin = 0b11010110

# Digit separators
large = 1_000_000

A leading zero is not permitted in decimal integers, except for 0 itself. 0644 is invalid; 0o644 is the octal form if that is the intent.

Floats require a decimal point or an exponent (or both). They support inf, +inf, -inf, nan, +nan, and -nan as special values. Digit separators are allowed in the integer and fractional parts .

# Floats
float1 = +1.0
float2 = 3.1415
float3 = -0.01

# Exponent
float4 = 5e+22
float5 = 1e06
float6 = -2E-2

# Both
float7 = 6.626e-34

# Special values
infinite = inf
not_a_number = nan

c. Booleans and the four date/time types

Booleans are true and false, lowercase only. There are no yes/no/on/off aliases, and no capitalization variants.

enabled = true
debug = false

Date/time values follow RFC 3339 with TOML’s liberties: a space may replace the T separator, and fractional seconds may be any length . The four types are distinguished by their components.

# Offset date-time: absolute instant with timezone
odt1 = 1979-05-27T07:32:00Z
odt2 = 1979-05-27T00:32:00-07:00
odt3 = 1979-05-27T00:32:00.999999-07:00

# Local date-time: no timezone, wall-clock value
ldt1 = 1979-05-27T07:32:00
ldt2 = 1979-05-27T00:32:00.999999

# Local date: a day, no time
ld1 = 1979-05-27

# Local time: a time of day, no date
lt1 = 07:32:00
lt2 = 00:32:00.999999

The Z suffix and ยฑHH:MM offset mark an offset date-time. Without either, a value with both date and time is local. A value with only a date is a local date; only a time is a local time. Parsers return these as different types: JavaScript returns Date for offset date-times and strings for local forms, while Go uses distinct LocalDateTime, LocalDate, and LocalTime types .


Complete Example Session

# ============================================
# PART 1: STRINGS (FOUR FORMS)
# ============================================
basic = "Line one\nLine two"
literal = 'C:\Users\app'
multi_basic = """
Line one
Line two"""
multi_literal = '''
No \escaping here'''

# ============================================
# PART 2: INTEGERS
# ============================================
decimal = 42
negative = -17
hex = 0xDEADBEEF
octal = 0o755
binary = 0b11010110
separated = 1_000_000

# ============================================
# PART 3: FLOATS
# ============================================
pi = 3.1415
exponent = 5e+22
both = 6.626e-34
infinity = inf
nan_value = nan

# ============================================
# PART 4: BOOLEANS
# ============================================
enabled = true
debug = false

# ============================================
# PART 5: DATES AND TIMES
# ============================================
offset = 1979-05-27T07:32:00Z
local_dt = 1979-05-27T07:32:00
local_date = 1979-05-27
local_time = 07:32:00

# ============================================
# PART 6: THE PARSED TYPES
# ============================================
# basic: "Line one\nLine two" (string)
# literal: 'C:\Users\app' (string, backslashes preserved)
# decimal: 42 (integer)
# hex: 3735928559 (integer)
# pi: 3.1415 (float)
# enabled: true (boolean)
# offset: absolute instant (offset date-time)
# local_dt: wall-clock (local date-time, no timezone)
# local_date: a day (local date)
# local_time: a time of day (local time)

The parts covered the four string forms, integer formats, float formats with special values, booleans, the four date/time types, and the parsed type distinctions.


Quick Reference

String Forms

FormDelimiterEscapesMulti-line
Basic"..."YesNo
Multi-line basic"""..."""YesYes
Literal'...'NoNo
Multi-line literal'''...'''NoYes

Number Formats

TypeSyntaxNotes
Decimal integer42, -17, +99No leading zero
Hex integer0xDEADBEEFCase-insensitive digits
Octal integer0o755Prefix 0o
Binary integer0b11010110Prefix 0b
Float3.14, 5e+22Decimal point or exponent
Special floatsinf, -inf, nanLowercase only

Date/Time Types

TypeExampleTimezone
Offset date-time1979-05-27T07:32:00ZYes
Local date-time1979-05-27T07:32:00No
Local date1979-05-27No
Local time07:32:00No

Best Practices

โœ… Do This:

# Quote strings that look like numbers
version = "1.10"                                             # โœ…

# Use literal strings for paths and regex
path = 'C:\Users\app'                                        # โœ…

# Use digit separators for large numbers
budget = 1_000_000                                           # โœ…

# Use offset date-time when the instant matters
created = 2026-05-05T10:00:00Z                               # โœ…

โŒ Don’t Do This:

# Leading zero in decimal integer
octal_wrong = 0644                                           # โŒ

# Unquoted string
name = app                                                   # โŒ (bare key error)

# Capitalized boolean
enabled = True                                               # โŒ

# Date-time without timezone when instant is intended
created = 2026-05-05T10:00:00                                # โŒ (local, not UTC)

Common Pitfalls

PitfallWhy It HappensFix
0644 parse errorLeading zero forbiddenUse 0o644 for octal or quote as string
Path escape errorsBasic string processes \Use literal string '...'
True rejectedBooleans lowercase onlyUse true
Local date-time treated as UTCNo offset means localAdd Z or offset
Multi-line string has extra newlineOpening delimiter newline not trimmed in all parsersUse \ at line end or accept trim behavior

Real-World Examples

1. Version as string

version = "1.10"

2. Windows path as literal

path = 'C:\Users\app'

3. Regex as literal

pattern = '<\i\c*\s*>'

4. Hex color

color = 0xFF0000

5. Large number with separators

bytes = 1_073_741_824

6. Special float

timeout = inf

7. Offset date-time

created = 2026-05-05T10:00:00Z

8. Local date

birthday = 1990-01-15

9. Local time

alarm = 07:30:00

10. Multi-line description

description = """
Line one
Line two"""

Visual

String Form Decision

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  CHOOSING A STRING FORM                                 โ”‚
โ”‚                                                         โ”‚
โ”‚  Contains backslashes or quotes?                        โ”‚
โ”‚         โ”‚                                               โ”‚
โ”‚    โ”Œโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”                                          โ”‚
โ”‚    โ–ผ         โ–ผ                                          โ”‚
โ”‚   YES        NO                                         โ”‚
โ”‚    โ”‚         โ”‚                                          โ”‚
โ”‚    โ–ผ         โ–ผ                                          โ”‚
โ”‚  Literal   Multi-line?                                  โ”‚
โ”‚  '...'         โ”‚                                        โ”‚
โ”‚            โ”Œโ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”                                    โ”‚
โ”‚            โ–ผ       โ–ผ                                    โ”‚
โ”‚          YES      NO                                    โ”‚
โ”‚            โ”‚       โ”‚                                    โ”‚
โ”‚            โ–ผ       โ–ผ                                    โ”‚
โ”‚         """...""" "..."                                 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

The Four Date/Time Types

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  DATE/TIME DISAMBIGUATION                               โ”‚
โ”‚                                                         โ”‚
โ”‚  Has date AND time AND offset?                          โ”‚
โ”‚  โ†’ Offset date-time (absolute instant)                  โ”‚
โ”‚    1979-05-27T07:32:00Z                                 โ”‚
โ”‚                                                         โ”‚
โ”‚  Has date AND time, NO offset?                          โ”‚
โ”‚  โ†’ Local date-time (wall clock)                         โ”‚
โ”‚    1979-05-27T07:32:00                                  โ”‚
โ”‚                                                         โ”‚
โ”‚  Has date ONLY?                                         โ”‚
โ”‚  โ†’ Local date                                           โ”‚
โ”‚    1979-05-27                                           โ”‚
โ”‚                                                         โ”‚
โ”‚  Has time ONLY?                                         โ”‚
โ”‚  โ†’ Local time                                           โ”‚
โ”‚    07:32:00                                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Integer Prefixes

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  INTEGER FORMATS                                        โ”‚
โ”‚                                                         โ”‚
โ”‚  Decimal:   42      -17     +99                         โ”‚
โ”‚  Hex:       0xDEADBEEF     (0x prefix)                  โ”‚
โ”‚  Octal:     0o755          (0o prefix)                  โ”‚
โ”‚  Binary:    0b11010110     (0b prefix)                  โ”‚
โ”‚                                                         โ”‚
โ”‚  Leading zero in decimal: INVALID                       โ”‚
โ”‚  0644 โ†’ error                                           โ”‚
โ”‚  0o644 โ†’ octal                                          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

String Escapes

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  BASIC STRING ESCAPES                                   โ”‚
โ”‚                                                         โ”‚
โ”‚  \n   newline        \t   tab                           โ”‚
โ”‚  \"   quote          \\   backslash                     โ”‚
โ”‚  \u00E9   รฉ          \U0001F600   ๐Ÿ˜€                    โ”‚
โ”‚                                                         โ”‚
โ”‚  LITERAL STRINGS: no escapes                            โ”‚
โ”‚  'C:\Users'  โ†’  C:\Users (backslash preserved)          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Summary

ItemValue
String formsBasic, multi-line basic, literal, multi-line literal
Basic string escapes\n, \t, \", \\, \uXXXX, \UXXXXXXXX
Integer prefixes0x hex, 0o octal, 0b binary
Leading zeroForbidden in decimal integers
Float requirementDecimal point or exponent
Special floatsinf, -inf, nan
Booleanstrue, false (lowercase)
Date/time typesOffset, local date-time, local date, local time
RFC standardRFC 3339

Key takeaways:

  • TOML types are syntax-determined. A quoted value is a string; a bare number is a number. There is no resolver guessing whether NO is a boolean or a string, which is the format’s core advantage over YAML.
  • Four string forms serve different needs. Basic for escapes and Unicode, literal for paths and regex, multi-line variants for text blocks. The literal form exists because backslash-heavy strings are unreadable when escaped .
  • Integers have four bases and no leading zeros. 0x, 0o, and 0b prefixes are explicit; 0644 is an error, not octal .
  • Floats require a decimal point or exponent. 42 is an integer; 42.0 and 4e1 are floats. Special values inf and nan are lowercase.
  • Date/time has four types, not one. Offset date-times are absolute; local forms are wall-clock values without timezone. The distinction is encoded in the syntax and preserved by parsers .

Remember: TOML’s type system is small because configuration files need few types. Strings, numbers, booleans, and dates cover almost everything a build tool or application reads. The failures come from the edges: a leading zero in an integer, a backslash in a basic string, a local date-time mistaken for an absolute instant. When a value fails to parse, check the syntax first: is it quoted when it should be bare, or bare when it should be quoted? Is the boolean lowercase? Does the date have an offset if the instant matters? The type is in the syntax, and the syntax is the answer.

Was this helpful?


Stop using slow, ad-bloated tool sites! ๐Ÿคฎ

๐Ÿ”Ž Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
โœ… Finance (Mortgage, Interest, Inflation)
โœ… Tech (Base64, JSON, Dev Suite, IP)
โœ… Health (BMI, BMR, TDEE)
โœ… Productivity (Timer, Workspace, QR)

โšก๏ธ Fast & Private
๐Ÿ”’ No data leaves your device
๐Ÿ’Ž 100% Free

๐Ÿ”— Use it now: https://tools.kandz.me
๐Ÿ”– Bookmark itโ€”youโ€™ll need it later!