# Comments start with #
# Key-value pairs use = with no quotes around keys
title = "TOML Example"
name = "Tom Preston-Werner"
# Strings
basic_string = "Hello, World!"
literal_string = 'C:\Users\nodejs\templates' # No escaping in single quotes
multiline_basic = """
Line one
Line two"""
# Integers
positive_int = 42
negative_int = -17
hex_int = 0xDEADBEEF # Hexadecimal
octal_int = 0o755 # Octal
binary_int = 0b11010110 # Binary
# Floats
pi = 3.14159
scientific = 5e+22 # Scientific notation
negative_float = -0.01
# Booleans
enabled = true
disabled = false
# Dates and Times
date = 1979-05-27 # Date only
datetime = 1979-05-27T07:32:00Z # Full ISO 8601
local_datetime = 1979-05-27T07:32:00 # Local datetime
local_time = 07:32:00 # Time only
# Simple arrays (homogeneous)
colors = ["red", "green", "blue"]
numbers = [1, 2, 3, 4, 5]
# Multiline arrays
contributors = [
"John Doe",
"Jane Smith",
"Bob Johnson"
]
# Nested arrays
matrix = [[1, 2], [3, 4], [5, 6]]
# Mixed types (if all are compatible)
mixed = [1, 2.0, 3] # integers and floats ok together
# Table headers define sections
[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00
[database]
server = "192.168.1.1"
ports = [8000, 8001, 8002]
connection_max = 5000
enabled = true
# Nested tables using dot notation
[servers.alpha]
ip = "10.0.0.1"
role = "frontend"
[servers.beta]
ip = "10.0.0.2"
role = "backend"
# Inline tables for compact data
point = { x = 1, y = 2 }
color = { r = 255, g = 0, b = 0 }
# Useful for configuration objects
server = { host = "localhost", port = 8080, tls = false }
# Double brackets for array of tables (repeated sections)
[[products]]
name = "Hammer"
sku = 738594937
[[products]]
name = "Nail"
sku = 284758393
color = "gray"
# Nested array of tables
[[fruits]]
name = "apple"
[[fruits.varieties]]
name = "red delicious"
[[fruits.varieties]]
name = "granny smith"
[[fruits]]
name = "banana"
[[fruits.varieties]]
name = "plantain"
# Package configuration (like Cargo.toml)
[package]
name = "my-project"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2021"
[dependencies]
serde = "1.0"
tokio = { version = "1.0", features = ["full"] }
# Application settings
[app]
name = "MyApp"
debug = true
[app.database]
host = "localhost"
port = 5432
username = "admin"
[app.logging]
level = "info"
format = "json"
outputs = ["stdout", "file"]
# Environment-specific config
[development]
debug = true
api_url = "http://localhost:3000"
[production]
debug = false
api_url = "https://api.example.com"
# Dotted keys create nested structures
user.name = "Alice"
user.email = "alice@example.com"
user.age = 30
# Equivalent to:
[user]
name = "Alice"
email = "alice@example.com"
age = 30
# Group related settings in tables
[server]
host = "0.0.0.0"
port = 8080
# Use arrays of tables for lists of similar items
[[users]]
name = "admin"
role = "administrator"
[[users]]
name = "guest"
role = "viewer"
# Use inline tables for simple nested data
theme = { primary = "#3490dc", secondary = "#ffed4e" }
# Use multiline strings for long text
description = """
This is a long description that spans
multiple lines for better readability."""