I was playing around to learn how embedding works. http://play.golang.org/p/oHOim4G1-l
When I marshalled Child struct it marshals as {}
. Why does it marshal like this?
I was playing around to learn how embedding works. http://play.golang.org/p/oHOim4G1-l
When I marshalled Child struct it marshals as {}
. Why does it marshal like this?
Your JSON dictionary is empty because none of the fields of the struct (or any of the structures embedded inside the struct) are exported.
If you change the field names to start with an upper case letter, then the encoding/json
module will be able to see them. Of course since you've also got methods called Name
and Value
, you'll need to call them something else to avoid a conflict.