Skip to main content
In Bun, TOML is a first-class citizen alongside JSON, JSON5, and YAML. You can:
  • Parse TOML strings with Bun.TOML.parse
  • import & require TOML files as modules at runtime (including hot reloading & watch mode support)
  • import & require TOML files in frontend apps via 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 inf and nan
  • Booleans: true and false
  • 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

You can import TOML files directly as ES modules. The TOML content is parsed and made available as both default and named exports:
config.toml

Default Import

app.ts

Named Imports

You can destructure top-level TOML tables as named imports:
app.ts
Or combine both:
app.ts

Import Attributes

You can also use import attributes to load any file as TOML:
app.ts

CommonJS

TOML files can also be required in CommonJS:
app.ts

Hot Reloading with TOML

When you run your application with bun --hot, changes to TOML files are automatically detected and reloaded without restarting:
config.toml
server.ts
Run with hot reloading:
terminal
Now when you modify config.toml, the changes are immediately reflected in your running application.

Bundler Integration

When you import TOML files and bundle with Bun, the TOML is parsed at build time and included as a JavaScript module:
terminal
This means:
  • Zero runtime TOML parsing overhead in production
  • Smaller bundle sizes
  • Tree-shaking support for unused properties (named imports)

Dynamic Imports

TOML files can be dynamically imported: