You want to use the omitempty option
type MyStruct struct {
Name string `json:"name,omitempty"`
Age int `json:"age"`
Email string `json:"email,omitempty"`
}
If you want Age to be optional as well you have to use a pointer, since the zero value of an int isn’t really “empty”
type MyStruct struct {
Name string `json:"name,omitempty"`
Age *int `json:"age,omitempty"`
Email string `json:"email,omitempty"`
}