-
Notifications
You must be signed in to change notification settings - Fork 44
Description
I want to be not-so-strict about key capitalization when parsing YAML. At times, I prefer the behavior of Go's encoding/json package that matches keys to fields regardless of case, kinda:
If multiple struct fields match an object key, an exact case match is preferred over a case-insensitive one.
Being case-sensitive by default seems appropriate, and Go's unstable encoding/json/v2 package has taken that approach. There is a MatchCaseInsensitiveNames option so that "JSON object members are matched against Go struct fields using a case-insensitive match of the name."
The v2 package also looks at a case:ignore struct tag, but I cannot tell from the documentation if it is exactly the same as that option:
The 'ignore' value specifies that matching is case-insensitive where dashes and underscores are also ignored.
This last description sounds like perhaps the broadest interpretation of what I'm thinking. It sounds like that is meant to disregard PascalCase vs camelCase vs snake_case vs kebab-case, etc.
For example, I would like to be able to load this YAML into this Go value:
- something: one
- someThing: two
- SomeThing: threevar parsed []struct { Something string }
yaml.Load(data, &parsed)
parsed[0].Something == "one"
parsed[1].Something == "two"
parsed[2].Something == "three"