- Parse TOML strings with
Bun.TOML.parse import&requireTOML files as modules at runtime (including hot reloading & watch mode support)import&requireTOML files in frontend apps with Bun’s bundler
Runtime API
Bun.TOML.parse()
Parse a TOML string into a JavaScript object.
Supported TOML Features
Bun’s TOML parser supports the TOML v1.0 specification, including:- Strings: basic (
"...") and literal ('...'), including multi-line - Integers: decimal, hex (
0x), octal (0o), and binary (0b) - Floats: including
infandnan - Booleans:
trueandfalse - Arrays: including mixed types and nested arrays
- Tables: standard (
[table]) and inline ({ key = "value" }) - Array of tables:
[[array]] - Dotted keys:
a.b.c = "value" - Comments: using
#
Error Handling
Bun.TOML.parse() throws if the TOML is invalid:
Module Import
ES Modules
Import TOML files directly as ES modules. Bun parses the TOML and exposes it as both default and named exports:config.toml
Default Import
Named Imports
You can destructure top-level TOML tables as named imports:Import Attributes
Use an import attribute to load any file as TOML:CommonJS
You can alsorequire TOML files in CommonJS:
Hot Reloading with TOML
When you run your application withbun --hot, Bun detects changes to TOML files and reloads them without restarting:
config.toml
terminal
Bundler Integration
When you bundle with Bun, the bundler parses imported TOML at build time and includes it as a JavaScript module:terminal
- Zero runtime TOML parsing overhead in production
- Smaller bundle sizes
- Tree shaking of unused properties (named imports)