I am trying to generate a JSON payload based on a defined structure. I have found various examples of single array objects, but cannot find one that fits a multi array.
Example code (that doesn't work):
package main
import "encoding/json"
import "fmt"
type DiscMessage struct {
Embeds []struct {
Title string `json:"title"`
Description string `json:"description"`
URL string `json:"url"`
Color int `json:"color"`
} `json:"embeds"`
}
func main() {
var values = DiscMessage{Embeds{{"title1", "description1", "url1", 6545520}}}
encjson, _:= json.Marshal(values)
fmt.Println(string(encjson))
}
Intended output:
{
"embeds": [{
"title": "title1",
"description": "description1",
"url": "url1",
"color": 6545520
}]
}
What is the best approach to this? Eventually I will replace the values with variables, and the possibility of more containers, for example a full discord webhook (https://leovoel.github.io/embed-visualizer/)
Embeds structtoEmbeds []structin an attempt to have an array within an array. That compiles, but when I changed it I am unsure where to go from there.