In this case, even though we never set the value of the Size attribute, and set its omitempty tag,it still appears in the output. To solve this, use a struct pointer instead :
1 2 3 4 5 6 7
type Dog struct { Breed string WeightKg int // Now `Size` is a pointer to a `dimension` instance Size *dimension `json:",omitempty"` } // prints {"Breed":"pug","WeightKg":0}