I know that you explicitly mention "without writing a custom marshal", but if someone sees this and thinks that it should be avoided due to complexity, the custom marshaler to do what you want to do is very simple:
type MyStruct struct { Nickname string `json:"nickname"` EmailAddress string `json:"email_address"` PhoneNumber string `json:"phone_number"` MailingAddress string `json:"mailing_address"` all bool } func (ms MyStruct) MarshalJSON() ([]byte, error) { m := map[string]interface{}{}
If the all field must be specified by an external package, then the method can be defined in the structure, or the field can be made public (will not affect JSON, since it is encoded using a custom marshaler).
Runnable example on the playground: http://play.golang.org/p/1N_iBzvuW4
source share