JSON: omitzero
func main() {
type Address struct {
City string `json:"city"`
Country string `json:"country"`
}
type Payload struct {
Name string `json:"name,omitempty"`
Age int `json:"age,omitempty"`
DateOfBirth time.Time `json:"date_of_birth,omitempty"`
Address Address `json:"address,omitempty"`
Empty struct{} `json:"empty,omitempty"`
}
res, err := json.MarshalIndent(Payload{}, "", " ")
if err != nil {
panic(err)
}
fmt.Println(string(res))
}References
Last updated