mapstructure icon indicating copy to clipboard operation
mapstructure copied to clipboard

Decode into map with case insensitive keys

Open andig opened this issue 2 years ago • 2 comments

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.

andig avatar Sep 17 '22 16:09 andig

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)

mullerch avatar Oct 27 '22 09:10 mullerch

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

andig avatar Oct 27 '22 20:10 andig