mapstructure

A Go library for decoding generic map values into strongly typed structs, and back again.

Library
Go
vv1.5.0
8,025stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
41/100Fair
Development Activity0
Maintenance0
Community64
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
75/100Good
Architecture75
Code Quality80
Innovation78
Learning Curve65

mapstructure is a lightweight, dependency-free Go library for converting map[string]interface{} values into native Go structs and vice versa. It solves a common problem in Go programs that decode loosely-typed data — JSON, YAML, HCL, command-line flags — where the shape of the data isn’t fully known until runtime.

Beyond basic decoding, mapstructure supports struct tags for field renaming, embedded struct squashing, weakly-typed input coercion, decode hooks for custom type conversions, and metadata tracking for unused keys. It’s a foundational dependency in tools like HashiCorp’s Terraform, Vault, and Packer, where configuration often arrives as untyped maps that need to become strongly typed Go values.

What You Get

  • Bidirectional decode/encode between maps and structs
  • Struct tag support for field renaming and squashing embedded types
  • Configurable decode hooks for custom type conversions
  • Weakly-typed input coercion for loosely-typed sources like CLI flags or PHP-style JSON
  • Metadata tracking of unused/unset keys for stricter validation

Common Use Cases

  • Configuration loading from parsed YAML/JSON/HCL into typed config structs
  • CLI flag binding where values arrive as loosely-typed strings
  • Plugin/RPC boundary decoding of untyped map payloads into internal Go types
  • Dynamic JSON handling when a payload’s shape isn’t known until a discriminator field is read

Under The Hood

Architecture mapstructure centers on a single exported Decode/NewDecoder entrypoint backed by an internal decoder type that dispatches by reflect.Kind across a flat, single-package codebase (mapstructure.go). Configuration is expressed through a DecoderConfig struct covering tag name, squash behavior, weak typing, and hook registration, while decode_hooks.go isolates the hook composition logic (DecodeHookFuncType/Kind/Value, ComposeDecodeHookFunc) as a separable concern from the core decode loop, and error.go aggregates per-field failures into a single multi-error value. There is no internal package layering — the entire library lives in one flat namespace, keeping the public surface small and predictable, though it means the reflection-heavy decode logic and configuration concerns share the same file.

Tech Stack The library has zero external dependencies, relying only on the Go standard library (reflect, encoding, errors, fmt, net, strconv, strings, time); go.mod declares go 1.14 as its floor. A GitHub Actions workflow (test.yml) runs go test ./... on push and pull request against a single Go version, providing basic regression coverage without a separate linting or static-analysis step.

Code Quality Testing is extensive and comprehensive relative to the library’s size: mapstructure_test.go alone carries roughly 2,800 lines across dozens of test functions, supplemented by a dedicated regression suite (mapstructure_bugs_test.go), hook-specific tests (decode_hooks_test.go), runnable Godoc examples (mapstructure_examples_test.go), and benchmark tests. Error handling is explicit and typed via the custom Error type, which implements both the standard error interface and errwrap.Wrapper for compatibility with multi-error tooling. No linter or formatter configuration is present in the repository.

API Design The public API favors progressive disclosure: the zero-config Decode(input, &output) call covers the common case, while NewDecoder(*DecoderConfig) exposes the full surface — tag renaming, squash, weak typing, decode hooks, and metadata — for advanced use. Package-level Godoc comments walk through each configuration option with inline examples, and struct tags follow conventions familiar from encoding/json, lowering the learning curve for anyone who has decoded JSON in Go before.

Used by 21 apps in this directory

Python
55%
Other

authentik

Authentication · Security

25,245

The self-hosted Identity Provider that replaces Okta, Auth0, and Entra ID with a unified SSO platform supporting SAML, OAuth2/OIDC, LDAP, RADIUS, and WebAuthn.

View details
92
Repo Health
81
Technical
67
Dependency
Built with
Python55%
TypeScript34%
Updated today
Go
82%
AGPL 3.0

Beta9

Developer Tools · AI Development · Data Engineering

1,762

Run AI workloads at scale with a Pythonic serverless runtime that handles GPU inference, background jobs, and sandboxes with zero infrastructure overhead.

View details
84
Repo Health
78
Technical
67
Dependency
Built with
Go82%
Python17%
Updated 3 days ago
Go
75%
AGPL 3.0

Coder

Devops · Developer Tools · Code Editors

14,299

Self-hosted cloud development environments and AI coding agents — defined in Terraform, connected via WireGuard, automatically shut down when idle.

View details
93
Repo Health
90
Technical
69
Dependency
Built with
Go75%
TypeScript23%
Updated today
Go
92%
AGPL 3.0

Cozy Stack

File Storage · Productivity

1,270

Self-hosted personal cloud platform that unifies your files, apps, and devices in one private space you fully control.

View details
94
Repo Health
77
Technical
67
Dependency
Built with
Go92%
Updated 2 days ago
Go
73%
Other

Flipt

Devops · Developer Tools

4,884

Git-native feature flag platform that stores, versions, and deploys feature toggles directly in your own Git repositories with no external database required.

View details
89
Repo Health
83
Technical
70
Dependency
Built with
Go73%
TypeScript26%
Updated yesterday
TypeScript
49%
AGPL 3.0

Grafana

Monitoring · Analytics

76,498

The open-source observability platform that unifies metrics, logs, and traces from any data source into dynamic, queryable dashboards.

View details
95
Repo Health
91
Technical
65
Dependency
Built with
TypeScript49%
Go45%
Updated today
Go
65%
Other

Hanko

Security · Authentication

9,016

Open source, self-hostable authentication platform with passkeys, SAML SSO, and OAuth — the privacy-first alternative to Auth0 and Clerk.

View details
89
Repo Health
81
Technical
69
Dependency
Built with
Go65%
TypeScript30%
Updated 2 days ago
Go
84%
MIT

Hatchet

AI Development · Developer Tools · Automation

7,812

A Postgres-backed orchestration engine for background tasks, AI agents, and durable workflows that replaces Redis queues and multi-datastore durable execution platforms with a single self-hostable service.

View details
88
Repo Health
83
Technical
68
Dependency
Built with
Go84%
PLpgSQL11%
Updated today
TypeScript
71%
Other

highlight.io

Developer Tools · Analytics · Monitoring

9,373

Open-source full-stack monitoring that unifies session replay, error tracking, logging, and distributed tracing so you can stop context-switching between tools.

View details
70
Repo Health
78
Technical
65
Dependency
Built with
TypeScript71%
Go16%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search