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 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
  • 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

Import TOML files directly as ES modules. Bun parses the TOML and exposes it as both default and named exports:
config.toml

Default Import

https://mintcdn.com/bun-1dd33a4e/JUhaF6Mf68z_zHyy/icons/typescript.svg?fit=max&auto=format&n=JUhaF6Mf68z_zHyy&q=85&s=7ac549adaea8d5487d8fbd58cc3ea35bapp.ts

Named Imports

You can destructure top-level TOML tables as named imports:
https://mintcdn.com/bun-1dd33a4e/JUhaF6Mf68z_zHyy/icons/typescript.svg?fit=max&auto=format&n=JUhaF6Mf68z_zHyy&q=85&s=7ac549adaea8d5487d8fbd58cc3ea35bapp.ts
Or combine both:
https://mintcdn.com/bun-1dd33a4e/JUhaF6Mf68z_zHyy/icons/typescript.svg?fit=max&auto=format&n=JUhaF6Mf68z_zHyy&q=85&s=7ac549adaea8d5487d8fbd58cc3ea35bapp.ts

Import Attributes

Use an import attribute to load any file as TOML:
https://mintcdn.com/bun-1dd33a4e/JUhaF6Mf68z_zHyy/icons/typescript.svg?fit=max&auto=format&n=JUhaF6Mf68z_zHyy&q=85&s=7ac549adaea8d5487d8fbd58cc3ea35bapp.ts

CommonJS

You can also require TOML files in CommonJS:
https://mintcdn.com/bun-1dd33a4e/JUhaF6Mf68z_zHyy/icons/typescript.svg?fit=max&auto=format&n=JUhaF6Mf68z_zHyy&q=85&s=7ac549adaea8d5487d8fbd58cc3ea35bapp.ts

Hot Reloading with TOML

When you run your application with bun --hot, Bun detects changes to TOML files and reloads them without restarting:
config.toml
https://mintcdn.com/bun-1dd33a4e/JUhaF6Mf68z_zHyy/icons/typescript.svg?fit=max&auto=format&n=JUhaF6Mf68z_zHyy&q=85&s=7ac549adaea8d5487d8fbd58cc3ea35bserver.ts
Run with hot reloading:
terminal

Bundler Integration

When you bundle with Bun, the bundler parses imported TOML at build time and includes it as a JavaScript module:
terminal
This means:
  • Zero runtime TOML parsing overhead in production
  • Smaller bundle sizes
  • Tree shaking of unused properties (named imports)

Dynamic Imports

You can also dynamically import TOML files: