I have a struct with some fields as follows:
type Test struct {
ID int `json:"id"`
Active bool `json:"active"`
Object []obj.Object `json:"objects"`
}
Then some handler functions that encode Test objects to JSON as a response, but in one of the functions, I want to omit the last field "objects" from the response. I know json:"-"
omits it but problem is I need that field for the others functions.
The way I encode the object to JSON is using this method:
json.NewEncoder(w).Encode(t)
Is there a way I can achieve that? Thanks in advance!