Re:Go: Ten years and climbing
by christophilus on Thursday September 21, 2017 @10:20PM
(#15308969)
Yeah. The repeating the field, only camelCased, in JSON annotations feels needlessly painful to me. Subjective, I know, but that kind of painfulness seems pervasive in my (brief) dabbling with Go, and is one of the main reasons I moved on.
[ Parent
| on HN ]
The json annotation is optional, but very powerful since it allows you to set the mapped name of the field to any name you like, allowing you to map json fields with snake_case, CamelCase, kebab-case, etc.
One alternative to writing struct tags by hand is to write a little generator code to map the field names from, say, a reference .json, then calling `go generate` as part of your build process.
I've wondered whether a wrapper library could do rule-based field name mapping automatically with Go's reflection facilities (which could be a productivity win), but I haven't really looked at it closely.