I have data like following
{
"cars": {
"toyota": [
"sedan",
"pickup"
],
"honda": [
"sedan",
"couple",
"pickup"
]
....
}
}
The list might continue grow. I am trying to find out a proper struct to server the data and return to A http responsewriter.
the struct that I had.
type Autos struct {
Cars struct {
Toyota []string `json:"toyota"`
Honda []string `json:"honda"`
} `json:"cars"`
}
But the above struct has predefined "Toyota" "Honda"
I am looking for a way to only use one or two struct to represent the data structure. Thanks in advance.
You can do:
Here's a full working example, that prints "coupe":
Playground link