/
Depends on
- dh-golang (dh-sequence-golang)
- golang-defaults (golang-any)
- debhelper-compat
Used by
- apptainer 1.4.5-2
- direnv 2.37.1-1
- dnscrypt-proxy 2.1.16+ds1-1
- docker.io 28.5.2+dfsg4-2
- docker.io 28.5.2+dfsg4-3
- fq 0.9.0-2
- golang-github-aquasecurity-go-dep-parser 0.0~git20220110.4a30ebc-3
- golang-github-containers-common 0.67.1-2
- golang-github-containers-storage 1.62.0-3
- golang-github-fahedouch-go-logrotate 0.2.1-1.1
- golang-github-gonvenience-ytbx 1.4.4-1.1
- golang-github-linbit-golinstor 0.63.0-1
- golang-github-lorenzosaino-go-sysctl 0.3.1+ds1-1
- golang-github-maypok86-otter 2.3.0+debian-2
- golang-github-miekg-mmark 1.3.6+dfsg-3
- golang-github-nicksnyder-go-i18n.v2 2.6.1-1
- golang-github-pelletier-go-toml 1.9.5-1
- golang-github-thoas-go-funk 0.9.3-1
- golang-github-traefik-paerser 0.2.0-1
- golang-github-urfave-cli-v2 2.25.7-5
Show 15 more
- golang-github-xenolf-lego 4.35.2-2
- golang-gopkg-hlandau-easyconfig.v1 1.0.17-5
- golang-honnef-go-tools 2026.1-3
- influxdb 1.6.7~rc0-2
- kind 0.31.0-2
- mmark 2.2.25+dfsg1-2
- molly-brown 0.0~git20230820.2068c3b-2
- dnscrypt-proxy 2.1.18+ds1-1
- docker.io 28.5.2+dfsg4-4
- gokr-rsync 0.3.6-1
- golang-github-containers-storage 1.64.0-1
- golang-github-maypok86-otter 2.3.0+debian-3
- golang-github-urfave-cli-v2 2.27.7-1
- golang-github-xenolf-lego 4.35.2-3
- golang-honnef-go-tools 2026.1-4
README (full)
TOML stands for Tom's Obvious, Minimal Language. This Go package provides a
reflection interface similar to Go's standard library json and xml packages.
Compatible with TOML version v1.1.0.
Documentation: https://pkg.go.dev/github.com/BurntSushi/toml
See the releases page for a
changelog; this information is also in the git tag annotations (e.g. git show v0.4.0).
This library requires Go 1.18 or newer; add it to your go.mod with:
% go get github.com/BurntSushi/toml@latest
It also comes with a TOML validator CLI tool:
% go install github.com/BurntSushi/toml/cmd/tomlv@latest
% tomlv some-toml-file.toml
Examples
For the simplest example, consider some TOML file as just a list of keys and values:
Age = 25
Cats = [ "Cauchy", "Plato" ]
Pi = 3.14
Perfection = [ 6, 28, 496, 8128 ]
DOB = 1987-07-05T05:45:00Z
Which can be decoded with:
type Config struct {
Age int
Cats []string
Pi float64
Perfection []int
DOB time.Time
}
var conf Config
_, err := toml.Decode(tomlData, &conf)
You can also use struct tags if your struct field name doesn't map to a TOML key value directly:
some_key_NAME = "wat"
type TOML struct {
ObscureKey string `toml:"some_key_NAME"`
}
Beware that like other decoders only exported fields are considered when encoding and decoding; private fields are silently ignored.
Using the Marshaler and encoding.TextUnmarshaler interfaces
Here's an example that automatically parses values in a mail.Address:
contacts = [
"Donald Duck <[email protected]>",
"Scrooge McDuck <[email protected]>",
]
Can be decoded with:
// Create address type which satisfies the encoding.TextUnmarshaler interface.
type address struct {
*mail.Address
}
func (a *address) UnmarshalText(text []byte) error {
var err error
a.Address, err = mail.ParseAddress(string(text))
return err
}
// Decode it.
func decode() {
blob := `
contacts = [
"Donald Duck <[email protected]>",
"Scrooge McDuck <[email protected]>",
]
`
var contacts struct {
Contacts []address
}
_, err := toml.Decode(blob, &contacts)
if err != nil {
log.Fatal(err)
}
for _, c := range contacts.Contacts {
fmt.Printf("%#v\n", c.Address)
}
// Output:
// &mail.Address{Name:"Donald Duck", Address:"[email protected]"}
// &mail.Address{Name:"Scrooge McDuck", Address:"[email protected]"}
}
To target TOML specifically you can implement UnmarshalTOML TOML interface in
a similar way.
More complex usage
See the _example/ directory for a more complex example.
| dir | .github/ |
| dir | _example/ |
| dir | cmd/ |
| dir | debian/ |
| dir | internal/ |
| dir | ossfuzz/ |
| dir | testdata/ |
| file | .gitignore |
| file | COPYING |
| file | README.md |
| file | bench_test.go |
| file | decode.go |
| file | decode_test.go |
| file | deprecated.go |
| file | doc.go |
| file | encode.go |
| file | encode_test.go |
| file | error.go |
| file | error_test.go |
| file | example_test.go |
| file | fuzz_test.go |
| file | go.mod |
| file | lex.go |
| file | lex_test.go |
| file | meta.go |
| file | parse.go |
| file | toml_test.go |
| file | type_fields.go |
| file | type_toml.go |