So we can load files like these:
hosts:
toto:
hostname: 1.2.3.4
port: 42
As well as
Hosts:
toto:
HostName: 1.2.3.4
Port: 42
Using
type File struct {
Hosts: []Host `yaml:Hosts`,
}
type Host struct {
HostName: string `yaml:HostName`
Port: int `yaml:Port`
}
For this, I'm running ToLower on the input data; considering that case sensitivity is part of the yaml spec, I think it's a better solution than changing the library (although it may be less convenient).
@dhiltonp, would love if you have a little time to review my PR so we can resolve this 3+ year old issue. I've also run into the same problem, where I'd like to ignore case-sensitivity on unmarshal.
Additional note, it's important to only ignore case-sensitivity for the key; the value should not be lowered
As a workaround I made this: https://github.com/moul/flexyaml
I would love to depreciate this repo in favor of an official solution :)
@moul, my PR only considers case insensitivity for the key; the value is kept as-is.
Looking at the mounting PRs backed up over a year, I'm wondering whether this project is still being maintained. I'm going to be working from a fork, unfortunately. In your case, you might do the same; feel free to include my PR if that suits your needs.
What the actual hell. We all understand the limitation of the first character having to be uppercase due to export requirements... but yaml is case-sensitive. Where the _hell_ does "unmarshalled using the field name lowercased as the default key" come from?!
You're making me tag every.... single... fkn field that has an uppercase character in it. Clearly my InstallVersion
field should be accepting the yaml field for installVersion
... not installversion
. For fuck's sake. Almost every... damn... field... has to be remapped manually. Not because my fields are strange, but because you arbitrarily decided on some absurd and broken "lowercase all the things".
Fix this in a v3 please. Backwards-incompatible as hell, but you'll be restoring expected behaviour. We're not even asking for complete case-insensitivity. Just that beyond that first unfortunate letter due to exported fields, you don't touch the rest of the string.
2 hours of my life wasted just to understand this "gotcha". And now every time I unmarshal, I have to work around this bug. And yes, it's a bug. No excuses, this is a bug. You're actually removing case-sensitivity from a case-sensitive format.