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

gogo get github.com/mitchellh/mapstructure

Methods

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.

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.