I need to show json's empty object {}
when do json.Marshal()
for a struct pointer. I can only output either null
value or empty struct value.
If the person
key is filled with &Person{}
or new(Person)
, it will show empty struct like below:
{
"data": {
"person": {
"name": "",
"age": 0
},
"created_date": "2009-11-10T23:00:00Z"
}
}
And if we don't initialize it at all, it will show null
.
{
"data": {
"person": null,
"created_date": "2009-11-10T23:00:00Z"
}
}
I want to show "person": {}
. Is it possible?
Go Playground for the complete code: https://play.golang.org/p/tT15G2ESPVc