mitchellh / mapstructure

Go library for decoding generic map values into native Go structures and vice versa.
https://gist.github.com/mitchellh/90029601268e59a29e64e55bab1c5bdc
MIT License
7.93k stars 677 forks source link

Decode into map with case insensitive keys #306

Open andig opened 2 years ago

andig commented 2 years ago

I have a situation where I don't know the target struct and hence decode into a map. This will create duplicate keys if input has multiple types of key case. It would be helpful if I could deduplicate the keys in a case insensitive way.

mullerch commented 2 years ago

https://pkg.go.dev/github.com/mitchellh/mapstructure#DecoderConfig : MatchName

// MatchName is the function used to match the map key to the struct
// field name or tag. Defaults to `strings.EqualFold`. This can be used
// to implement case-sensitive tag values, support snake casing, etc.
MatchName func(mapKey, fieldName [string](https://pkg.go.dev/builtin#string)) [bool](https://pkg.go.dev/builtin#bool)
andig commented 2 years ago

I don't think that applies here. This will match decoding into a struct, I'm decoding into a map?