A Go library for dynamically transforming structs into maps with chainable field selection and modification.
structomap is a Go library that dynamically converts Go structs into maps for easy serialization to JSON, XML, or other formats. It solves the problem of manually constructing API responses or data transformations by providing a chainable interface to select, omit, rename, and compute fields on the fly.
Go developers building web APIs, microservices, or any application needing flexible control over data serialization, especially when struct fields must be conditionally included or transformed.
Developers choose structomap for its clean, fluent API that eliminates boilerplate code, supports conditional logic, and enables reusable serializer patterns without requiring struct tags or external dependencies.
Easily and dynamically generate maps from Go static structures
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
The fluent interface with methods like Pick(), Omit(), and AddFunc() allows defining complex transformations without boilerplate, as demonstrated in the README's userSerializer example for dynamic field selection.
Functions like OmitIf() enable runtime decisions on field inclusion, such as hiding email based on a HideEmail flag, providing fine-grained control over serialization logic.
Helpers like UseSnakeCase() automatically convert map keys to common cases, simplifying output for APIs that require specific naming conventions without manual string manipulation.
TransformArray() processes slices or arrays uniformly, making it easy to serialize collections with consistent logic, as shown in the users array example for efficient batch operations.
Methods modify the serializer in place, which can lead to shared state issues if serializers are reused across goroutines or without cloning, as noted in the 'Building your own serializer' section where return values are ignored.
Relies on reflection to access struct fields, which may introduce overhead compared to compile-time approaches like code generation or struct tags, potentially impacting high-volume serialization tasks.
While it handles top-level structs well, complex nested structs often require additional manual code with AddFunc() or separate serializers, increasing boilerplate for deep object graphs.