Closed TLINDEN closed 9 months ago
The same behavior occurs with package json
(see https://play.golang.com/p/95ADPcmOZfl). The issue is that marshaling in Go only works with exported struct fields (that is, the first character must be an uppercase letter), so you need to use struct field tags to tell the package that the encoded field name is different from the exact struct field name. A JSON example: https://play.golang.com/p/cKikjpPuu2x
Hi,
thanks a lot! I seem to forget this upper case character thing regularly :)
Describe the bug When marshalling a struct containing the key
y
, the key is omitted. And, when marshalling a struct with two keysYES
andyes
only one of them makes it to the output.To Reproduce
Output:
Expected behavior According to the documentation:
I could not find any section where it describes this behavior.
Versions
Additional context I encountered a similar bug in gopkg.in/yaml.v3 and wanted to switch to TOML because of this just to discover a similar strange behavior.