{
"someKey": 1,
"myMap": {
"A": "v1",
"B": "v2"
}
}
config := viper.New()
config.AddConfigPath("myconfigpath")
config.SetConfigName("myconfig")
var myMap map[string]string
config.UnmarshalKey("myMap", &myMap)
myMap has all lower-cased keys.
Can somebody comment if it is expected or is it a bug ?
This doesn't seem to be documented anywhere but internally, Viper lowercases all keys which is weird: https://github.com/spf13/viper/blob/d9cca5ef33035202efb1586825bdbb15ff9ec3ba/viper.go#L1303
This goes against the YAML, TOML, and JSON specs where keys are case sensitive.
I will request viper authors to comment.
@spf13 any comment?
Just came across this today. Is there an option or workaround to disable this behaviour?
@wjdp #482 https://github.com/lnashier/viper
This issues is still there
@codemodify https://github.com/spf13/viper/pull/635 has been pending for almost a year and should give you better context on the state of this issue.
want a fix for this issue as well :(
@codemodify @ackratos this is not an easy fix as it goes directly against core Viper principles and goals. I'm working on it, but please keep in mind this is an open source project with a lot of users. A major change like this is not easy to pull in.
Thank you, completely understand, will it be ok to have this highlighted on the front page that can be used for making decisions when picking up tools ? The reason for that is because when you are half way through it is hard to drift away when you understand the limits
I've just hit this too, and it's most unexpected. I'm demarshalling a struct that contains a map. The struct fields demarshall fine but the map keys all come out lower case, which is unexpected.
I had to make the map into a slice to work around this, making the key a field value of the slice element. Lucky I have control of the data structure.
But still want to see viper handling case-sensitive map keys locally.
Most helpful comment
I had to make the map into a slice to work around this, making the key a field value of the slice element. Lucky I have control of the data structure.
But still want to see viper handling case-sensitive map keys locally.