# mitchellh/mapstructure

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/mitchellh-mapstructure).**

8,033 stars · 721 forks · Go · MIT · archived

## Links

- GitHub: https://github.com/mitchellh/mapstructure
- Homepage: https://gist.github.com/mitchellh/90029601268e59a29e64e55bab1c5bdc
- awesome-repositories: https://awesome-repositories.com/repository/mitchellh-mapstructure.md

## Description

mapstructure is a reflection-based library for the bidirectional encoding and decoding of generic map data into native typed Go structures. It functions as a tool for transforming loosely typed map values into specific structs and encoding those structs back into maps.

The library utilizes Go reflection to map generic data keys to struct fields during runtime. It supports the transformation of untyped data from dynamic sources or configuration files into type-safe native structures.

The mapping process includes recursive traversal of nested maps and slices, as well as the use of struct tags to resolve custom destination names. It also provides capabilities for weakly-typed value coercion and custom type conversion via hook functions.

## Tags

### Software Engineering & Architecture

- [Reflection-Based Map Mapping](https://awesome-repositories.com/f/software-engineering-architecture/metadata-attachments/struct-tags/reflection-based-map-mapping.md) — Uses Go reflection to inspect target structure types and dynamically map keys from generic maps to typed fields.
- [Struct Tags](https://awesome-repositories.com/f/software-engineering-architecture/metadata-attachments/struct-tags.md) — Uses struct tags to resolve custom destination names for map keys during the decoding process.
- [Recursive Struct Traversal](https://awesome-repositories.com/f/software-engineering-architecture/recursive-struct-traversal.md) — Walks through nested maps and slices to decode complex hierarchical data into deeply nested Go structures.
- [Reflection-Based Unmarshallers](https://awesome-repositories.com/f/software-engineering-architecture/reflection-based-unmarshallers.md) — Uses Go reflection to map generic data keys to specific struct fields during runtime.
- [Value Type Conversions](https://awesome-repositories.com/f/software-engineering-architecture/data-schema-validation/data-type-validation/value-type-conversions.md) — Employs custom hook functions to transform data types when the source map value differs from the target field.
- [Type Coercion Utilities](https://awesome-repositories.com/f/software-engineering-architecture/type-coercion-utilities.md) — Automatically converts between compatible types such as strings and integers to handle flexible input.
- [Type-Safe Data Handling](https://awesome-repositories.com/f/software-engineering-architecture/type-safe-data-handling.md) — Ensures data safety by validating and mapping untyped map entries into native Go types during decoding.

### Data & Databases

- [Hash-to-Struct Hydrators](https://awesome-repositories.com/f/data-databases/data-mapping/struct-hydrators/row-to-struct-mappers/hash-to-struct-hydrators.md) — Directly populates the memory addresses of target structures from generic maps using Go reflection.
- [Dynamic Data Mapping](https://awesome-repositories.com/f/data-databases/dynamic-data-mapping.md) — Converts generic map values into typed Go structures when the input schema is not known beforehand.
- [Generic Map Transformations](https://awesome-repositories.com/f/data-databases/generic-map-transformations.md) — Converts typed Go structures back into generic maps for flexible data transmission or storage in non-typed systems.
- [Struct Mapping](https://awesome-repositories.com/f/data-databases/hash-data-structures/struct-mapping.md) — Transforms loosely typed map data into native Go structs and encodes structs back into maps.
- [Map-to-Struct Decoders](https://awesome-repositories.com/f/data-databases/map-to-struct-decoders.md) — Transforms generic map values into typed structures using reflection and conditional logic to ensure correct mapping. ([source](https://cdn.jsdelivr.net/gh/mitchellh/mapstructure@main/README.md))
- [Struct-to-Map Encoders](https://awesome-repositories.com/f/data-databases/struct-to-map-encoders.md) — Transforms typed structures into generic map formats to facilitate flexible data transmission and storage. ([source](https://cdn.jsdelivr.net/gh/mitchellh/mapstructure@main/README.md))

### Programming Languages & Runtimes

- [Go Data Mapping Libraries](https://awesome-repositories.com/f/programming-languages-runtimes/go-data-mapping-libraries.md) — Provides a dedicated library for converting generic map values into typed Go structures and vice versa.

### DevOps & Infrastructure

- [Configuration File Loading](https://awesome-repositories.com/f/devops-infrastructure/configuration-management/file-based-configuration/configuration-file-loading.md) — Loads settings from flexible formats like JSON or YAML into strongly typed Go structs.

### Part of an Awesome List

- [Data Serialization](https://awesome-repositories.com/f/awesome-lists/devtools/data-serialization.md) — Decoding generic maps into native Go structures.
- [Development Utilities](https://awesome-repositories.com/f/awesome-lists/devtools/development-utilities.md) — Decodes map values into Go structs.
