Small and Fast TOML Parser

1.6.1 · active · verified Tue Apr 21

smol-toml is a JavaScript and TypeScript library designed for parsing and serializing TOML (Tom's Obvious, Minimal Language) documents. Currently at version 1.6.1, it offers a small, fast, and highly compliant implementation of the TOML specification, supporting the latest TOML 1.1.0 standard since version 1.6.0. It maintains a regular release cadence with recent updates addressing security vulnerabilities and feature enhancements. Differentiating itself from other often outdated or unmaintained TOML parsers in the JavaScript ecosystem, smol-toml is noted as the most downloaded TOML parser on npm, actively used in production systems. While generally robust, it explicitly notes some non-compliance with the `toml-test` suite for performance reasons, such as not rejecting invalid UTF-8 or certain invalid dates. It also provides options for handling integers as BigInts to prevent precision loss, a feature introduced in v1.4.0.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates parsing a TOML string into a JavaScript object and then stringifying the object back into a TOML string, including options for BigInt parsing.

import { parse, stringify } from 'smol-toml';

const tomlDoc = `
[database]
driver = "postgresql"
server.host = "127.0.0.1"
server.port = 3307
float_val = 1.0
int_val = 9223372036854775807
`;

console.log('--- Original TOML Document ---');
console.log(tomlDoc);

// Parse the TOML document
const parsedConfig = parse(tomlDoc, { parseBigInt: true }); // parseBigInt for large integers
console.log('\n--- Parsed JavaScript Object ---');
console.log(JSON.stringify(parsedConfig, null, 2));

// Stringify the JavaScript object back to TOML
const stringifiedToml = stringify(parsedConfig);
console.log('\n--- Stringified TOML Document ---');
console.log(stringifiedToml);

// Example with default export
import TOML from 'smol-toml';
const parsedWithDefault = TOML.parse(tomlDoc);
console.log('\n--- Parsed with default export ---');
console.log(JSON.stringify(parsedWithDefault.database, null, 2));

view raw JSON →