toml

A reflection-based TOML decoder and encoder for Go, built to feel like encoding/json.

Library
Go
vv1.6.0
5,012 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
65 /100 Good
Development Activity 48
Maintenance 36
Community 76
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
76 /100 Good
Architecture 78
Code Quality 82
Innovation 55
Learning Curve 90

BurntSushi/toml is a Go library for decoding and encoding TOML documents. It provides a reflection-based API deliberately modeled on Go’s standard library encoding/json and encoding/xml packages, so toml.Decode, toml.Unmarshal, and toml.DecodeFile map values straight onto exported struct fields, with toml:"..." tags available for keys that don’t match Go identifiers directly.

The package targets TOML v1.0.0 compliance and is validated against the official toml-test conformance suite, which ships vendored inside the repo’s internal/toml-test package along with hundreds of valid/invalid fixture files. It also supports encoding.TextUnmarshaler/TextMarshaler and a package-specific Unmarshaler/Marshaler interface pair for custom type conversion, plus a Primitive type for deferring decode decisions until runtime.

Beyond the library, the module ships three CLI tools under cmd/: tomlv, a standalone TOML validator that also prints the inferred type of each key; and toml-test-decoder / toml-test-encoder, harnesses used to run the official toml-test suite against this implementation. As one of the original and most widely depended-on Go TOML libraries, it’s a common transitive dependency across the Go ecosystem, including tools like Hugo and Viper.

What You Get

  • Reflection-based decode/encode API - toml.Decode, toml.Unmarshal, toml.DecodeFile, toml.DecodeFS, and matching Marshal/NewEncoder functions that populate or serialize Go structs directly.
  • Struct tag support - toml:"key_name" tags let TOML keys diverge from Go field naming conventions, matching encoding/json conventions.
  • Custom (un)marshaling interfaces - implement toml.Unmarshaler/Marshaler or the standard encoding.TextUnmarshaler/TextMarshaler interfaces for full control over how a type is decoded or encoded.
  • Primitive deferred-decode type - decode a value into an opaque Primitive and resolve its concrete type later with PrimitiveDecode, avoiding reflection overhead when the shape isn’t known upfront.
  • Detailed ParseError type - structured parse errors carrying message, position (line/column), and last-parsed-key context, with ErrorWithPosition/ErrorWithUsage helpers for pretty-printed diagnostics.
  • Bundled tomlv CLI validator - a standalone command-line tool (cmd/tomlv) that validates a TOML file and can print the inferred type of every key.

Common Use Cases

  • Application configuration files - Go CLIs and servers decode a config.toml straight into a typed config struct at startup.
  • TOML validation in CI/tooling - the bundled tomlv binary is installed and run as a standalone linter/validator step against TOML files without writing any Go code.
  • Round-tripping structured data - encoding Go structs back out to TOML for generated config files, exported settings, or scaffolding templates.
  • Conformance testing other TOML implementations - the toml-test-decoder/toml-test-encoder binaries plug this package into the language-agnostic toml-test suite to validate spec compliance.

Under The Hood

Architecture The library is organized as a classic lexer/parser/decoder pipeline in a flat package: lex.go tokenizes raw TOML text, parse.go builds an internal tree of parsed values from that token stream, and decode.go walks the parse tree with reflect to populate the caller’s Go value, consulting type_fields.go for struct-tag-aware field resolution and type_toml.go/internal/tz.go for TOML-specific type handling (datetimes, local vs. offset times). encode.go performs the reverse pass, walking a Go value via reflection to emit TOML syntax, and meta.go exposes MetaData so callers can introspect which keys were actually present in the source document after a decode. error.go defines a single structured ParseError type threaded through the lexer and parser so failures carry position and last-key context all the way out to the caller, rather than being flattened into a plain string early. The cmd/ directory layers three thin CLI binaries (tomlv, toml-test-decoder, toml-test-encoder) directly on top of the public package API, and internal/toml-test vendors the official language-agnostic TOML conformance suite (test runner plus hundreds of fixture files) so the parser’s spec compliance is checked mechanically rather than by hand-written cases alone.

Tech Stack This is a dependency-free Go module (go.mod declares only module github.com/BurntSushi/toml and go 1.21, no third-party requires) targeting TOML v1.0.0 per the package doc comment. It uses only the Go standard library — reflect, encoding, encoding/json (for a compatibility shim), io/io/fs, math, os, strconv, strings, and time — which keeps it trivially embeddable as a transitive dependency without pulling in a wider dependency graph. The CLI tools under cmd/ are plain main packages built with the standard go build/go install toolchain; there’s no external build system, code generator, or ORM/framework layer since this is a pure parsing/serialization library.

Code Quality Testing is extensive: decode_test.go and encode_test.go alone carry dozens of table-driven test functions covering type coercion, tag handling, and error paths, complemented by lex_test.go, error_test.go, example_test.go (runnable doc examples), a bench_test.go benchmark suite, and fuzz_test.go wired into a dedicated OSS-Fuzz CI workflow (.github/workflows/cifuzz.yml) alongside a standard test.yml CI pipeline. Beyond hand-written Go tests, the package is checked against the vendored official toml-test conformance suite (internal/toml-test), which exercises hundreds of valid/invalid TOML fixtures — a rigor level uncommon even among mature parsing libraries. Error handling is explicit and typed via the structured ParseError (position, last key, message, optional usage guidance) rather than opaque strings, and public functions consistently return error per Go convention. Naming follows idiomatic Go conventions throughout, and a CONTRIBUTING.md documents expectations for contributors.

API Design The public API is deliberately shaped to feel like encoding/json: Decode, Unmarshal, DecodeFile, DecodeFS for reading, Marshal/NewEncoder for writing, and toml:"..." struct tags for key mapping — a Go developer already familiar with the standard library’s JSON package can be productive with almost no new concepts to learn. Extension points follow the same shape as the standard library’s marshaling interfaces (encoding.TextMarshaler/TextUnmarshaler, plus a package-specific Marshaler/Unmarshaler pair), so custom type conversion requires no boilerplate beyond implementing one familiar method. The MetaData return value and Primitive deferred-decode type are the two API surfaces that go beyond a typical JSON library, both addressing TOML-specific needs (detecting which keys were actually set, and delaying decode decisions) without complicating the common-case call. Documentation is strong: doc.go gives a package-level overview, example_test.go provides compiler-checked runnable examples, and the README walks through struct tags and custom unmarshaling with complete code samples.

Used by 14 apps in this directory

Vue
43%
MIT

Alexandrie

Collaboration · Knowledge Management · Note Taking

2,777

The open-source, offline-first Notion, Obsidian & Confluence alternative with multi-tenant teams, OIDC/SSO, and one-command Docker deployment.

View details
86
Repo Health
73
Technical
74
Dependency
Built with
Vue 43%
TypeScript 41%
Go 13%
Updated 2 weeks ago
Go
98%
Apache 2.0

Caddy

Devops · Security

76,128

The only web server that obtains and renews TLS certificates automatically, with HTTP/1-2-3 support and zero dependency on external runtimes.

View details
92
Repo Health
86
Technical
75
Dependency
Built with
Go 98%
Updated 2 weeks ago
Go
80%
Apache 2.0

Dolt

Data Engineering · Databases · Developer Tools

24,532

The SQL database you can branch, merge, diff, and clone — Git for your data, MySQL-compatible and ready for multi-agent AI workflows.

View details
90
Repo Health
9
Technical
65
Dependency
Built with
Go 80%
Shell 19%
Updated 2 weeks ago
Ruby
67%
Other

GitLab

Developer Tools · Devops

24,552

The complete DevOps platform that unifies Git hosting, CI/CD, issue tracking, and security scanning into a single self-hostable application.

View details
87
Repo Health
86
Technical
67
Dependency
Built with
Ruby 67%
JavaScript 20%
Updated 1 weeks ago
TypeScript
48%
AGPL 3.0

Grafana

Analytics · Monitoring

76,962

The open-source observability platform that unifies metrics, logs, and traces from any data source into dynamic, queryable dashboards.

View details
95
Repo Health
91
Technical
63
Dependency
Built with
TypeScript 48%
Go 46%
Updated 1 weeks ago
Go
64%
MIT

hoop

Monitoring · Security

823

A wire-protocol gateway that enforces data masking, command blocking, approval workflows, and full session recording for engineers and AI agents accessing production infrastructure.

View details
85
Repo Health
80
Technical
64
Dependency
Built with
Go 64%
Clojure 17%
JavaScript 11%
Updated 2 weeks ago
Go
99%
Apache 2.0

klaw

AI Agents · Devops

636

kubectl for AI Agents — manage, schedule, and scale your AI workforce with a single binary that deploys in seconds.

View details
38
Repo Health
74
Technical
82
Dependency
Built with
Go 99%
Updated 6 months ago
Go
98%
Apache 2.0

Nightingale

Monitoring

13,315

Open-source alerting engine that connects to any time-series or log data source and routes alarms to 20+ notification channels with AI-assisted triage.

View details
95
Repo Health
77
Technical
67
Dependency
Built with
Go 98%
Updated 2 weeks ago
C
76%
AGPL 3.0

TDengine

Databases

25,146

A high-performance, open-source time-series database built in C for IoT, connected vehicles, and industrial monitoring workloads, with built-in stream processing, caching, and data subscription.

View details
97
Repo Health
71
Technical
68
Dependency
Built with
C 76%
C++ 16%
Updated 2 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers