API Reference
mapstructure
A library for decoding generic map values into Go structs, used by configuration loaders.
Official Documentation ↗CompatibilityThis documentation covers version
v1.5. Check the official docs for the latest API surface.Installation
go
go get github.com/mitchellh/mapstructureMethods
No methods match this filter.
mapstructure decodes maps produced by JSON, YAML, or env parsing into typed Go structs.
Key Features
- Struct mapping with tags
- Weak typing and hooks
- Reusable decoder configuration
Usage Notes
Pin a version and check the official docs for the API surface you depend on before upgrading.
Errors
The following points are quoted verbatim from the official documentation. 来源:https://pkg.go.dev/github.com/mitchellh/mapstructure · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:50:50.674Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.
- DecodeHookFunc ) DecodeHookFunc OrComposeDecodeHookFunc executes all input hook functions until one of them returns no error. (https://pkg.go.dev/github.com/mitchellh/mapstructure)
- If all hooks return an error, OrComposeDecodeHookFunc returns an error concatenating all error messages. (https://pkg.go.dev/github.com/mitchellh/mapstructure)
- Source Files ¶ View all Source files decode_hooks.go error.go mapstructure.go Click to show internal directories. (https://pkg.go.dev/github.com/mitchellh/mapstructure)
FAQ
- How do I change the struct tag?
- Set TagName in DecoderConfig, for example to config or json, so field mapping follows that tag.
- How do I convert custom types?
- Register a DecodeHookFunc that transforms source values before they are assigned to fields.
- Why is a field empty?
- The map key may not match the tag, or the field is unexported. Check both the tag name and field visibility.
Report a problem with this API docOpens a pre-filled issue on GitHub.