Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Toml | 4,104 | 6,163 | 2 months ago | 47 | June 25, 2022 | 13 | mit | Go | ||
TOML parser for Golang with reflection. | ||||||||||
Ffjson | 2,620 | 242 | 356 | 3 years ago | 2 | February 06, 2015 | 57 | apache-2.0 | Go | |
faster JSON serialization for Go | ||||||||||
Schema | 1,157 | 344 | 553 | 3 months ago | 6 | May 20, 2021 | 9 | bsd-3-clause | Go | |
Package gorilla/schema fills a struct with form values. | ||||||||||
Csvutil | 783 | 3 | 67 | a month ago | 22 | March 20, 2022 | mit | Go | ||
csvutil provides fast and idiomatic mapping between CSV and Go (golang) values. | ||||||||||
Jingo | 718 | 2 | 5 | 2 years ago | 7 | April 11, 2021 | apache-2.0 | Go | ||
This package provides the ability to encode golang structs to a buffer as JSON very quickly. | ||||||||||
Json Rust | 335 | 367 | 149 | 3 years ago | 53 | March 17, 2020 | 37 | other | Rust | |
JSON implementation in Rust | ||||||||||
Toml | 288 | 341 | 497 | 8 months ago | 6 | July 30, 2021 | 6 | mit | Go | |
TOML parser and encoder library for Golang | ||||||||||
Toolbox | 189 | 9 | 32 | 2 hours ago | 84 | March 14, 2022 | 5 | apache-2.0 | Go | |
Toolbox - go utility library | ||||||||||
Jettison | 141 | 2 | 3 months ago | 5 | March 21, 2022 | 1 | mit | Go | ||
Highly configurable, fast JSON encoder for Go | ||||||||||
Qs | 66 | 4 months ago | 8 | June 09, 2021 | mit | Go | ||||
Go module for encoding structs into URL query parameters |
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.0.0.
Documentation: https://godocs.io/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.13 or newer; add it to your go.mod with:
% go get github.com/BurntSushi/[email protected]
It also comes with a TOML validator CLI tool:
% go install github.com/BurntSushi/toml/cmd/[email protected]
% tomlv some-toml-file.toml
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.
Marshaler
and encoding.TextUnmarshaler
interfacesHere'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.
See the _example/
directory for a more complex example.