Here is a composite literal for your type:
resp := Music{ Genre: struct { Country string Rock string }{ Country: "Taylor Swift", Rock: "Aimee", }, }
playground example
You need to repeat the anonymous type in the literal. To avoid repetition, I recommend defining the type for the genre. In addition, use field tags to indicate lowercase names in the output.
type Genre struct { Country string `json:"country"` Rock string `json:"rock"` } type Music struct { Genre Genre `json:"genre"` } resp := Music{ Genre{ Country: "Taylor Swift", Rock: "Aimee", }, }
playground example
Cerise limΓ³n
source share