C.W.K.
Stream
Lesson 04 of 08 · published

Numbers, Booleans, Dates — Native Types

~10 min · toml, numbers, dates

Level 0Plaintext
0 XP0/64 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

TOML's biggest advantage over JSON: real dates

Numbers

  • Integer — 64-bit signed. 42, -17, 1_000_000 (digit grouping with underscores). Hex/octal/binary literals: 0xff, 0o755, 0b1010.
  • Float — IEEE 754 double. 3.14, 1e6, 1.5e-3. Special values: inf, -inf, nan (literal — JSON doesn't allow these).

Booleans

Lowercase only: true or false. Not True, not TRUE, not yes. The Norway problem can't happen here — there's exactly one way to write each.

Dates and times — the killer feature

  • Offset Date-Time — RFC 3339 with timezone. 1979-05-27T07:32:00-08:00. The most precise form.
  • Local Date-Time — no timezone. 1979-05-27T07:32:00.
  • Local Date1979-05-27.
  • Local Time07:32:00.

Native dates parse directly into datetime objects (Python), chrono::DateTime (Rust), time.Time (Go). No 'parse this string as ISO 8601' code in your config loader.

Principle: when your data has dates, prefer TOML over JSON. JSON forces 'string by convention' + a parser pass; TOML gives you a typed value out of the box. The downstream code is shorter, the bugs are fewer.

Code

Numbers — every form·toml
# Integers
int_dec    = 1_000_000
int_hex    = 0xff
int_oct    = 0o755
int_bin    = 0b1010
int_neg    = -17

# Floats
float_basic = 3.14
float_sci   = 6.022e23
float_neg   = -1.5e-3

# Special — TOML allows these, JSON doesn't
float_inf  = inf
float_ninf = -inf
float_nan  = nan
Booleans + the JSON contrast·toml
is_active = true
is_admin  = false

# These would all be parse errors:
# is_active = True
# is_active = TRUE
# is_active = yes
# is_active = 1
Dates — four flavors·toml
offset_dt = 1979-05-27T07:32:00-08:00
utc_dt    = 1979-05-27T07:32:00Z
local_dt  = 1979-05-27T07:32:00
local_d   = 1979-05-27
local_t   = 07:32:00
Python parse — typed out of the box·python
import tomllib
from datetime import datetime, date, time

data = tomllib.loads('''
started_at = 2026-05-04T01:30:11+09:00
launch_date = 2026-05-15
''')

assert isinstance(data['started_at'], datetime)
assert isinstance(data['launch_date'], date)
# No reviver, no string parsing — typed values out of the box.

External links

Exercise

Write a TOML config with a UTC timestamp, a local-only date, a hex-literal byte mask, and a digit-grouped integer. Parse with Python's tomllib and verify the types — datetime, date, int, int. Compare with the equivalent JSON: every date would be a string and you'd have to remember to parse them.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.