What would be the best way to represent the following in a struct / json string? -if even possible-
Data i would like to handle looks something like:
{{Database : "flowers" , Type : "sunflower" - Location : "behind"
- Height : "130"
, Type : "roses" - Time : "12:30"
- Date : "12-12-2019"
- Height : "150" },
{
Database : "fruits" , Type : "apple" - Height : "200"
, Type : "peer" - Location : "above"
, Type : "banana" - Color : "green" }}
Any hints where to start or any idea would be very helpfull and much appreciated.
maybe as below that you want:
[
{
"Database" : "flowers",
"Types" : [
{
"Type" : "sunflower",
"Location" : "behind",
"Height" : "130"
},
{
"Type" : "roses",
"Time" : "12:30",
"Date" : "12-12-2019",
"Height" : "150"
}
]
},
{
"Database" : "fruits",
"Types" : [
{
"Type" : "apple",
"Height" : "200"
},
{
"Type" : "peer",
"Location" : "above"
},
{
"Type" : "banana",
"Color" : "green"
}
]
}
]
There are many ways that you could represent this data in your code and in json, here is just a couple of ways you could section it dependent on what is important to you and what you would do with the data after it is in the structs/json.
type (
Plant struct {
Type string `json:"type"` //flowers or fruits
Attributes *PlantAttributes `json:"attributes"`
}
PlantAttributes struct {
Name string `json:"name"` //apple or roses etc
Location string `json:"location"`
Height string `json:"height"`
Time string `json:"time"`
Date string `json:"date"`
Color string `json:"color"`
}
)
or
type (
Flowers struct {
Type string `json:"type"` // apples or bananas
Attributes *PlantAttributes `json:"attributes"`
}
Fruit struct {
Type string `json:"type"` // sunflowers or roses
Attributes *PlantAttributes `json:"attributes"`
}
PlantAttributes struct {
Location string `json:"location"`
Height string `json:"height"`
Time string `json:"time"`
Date string `json:"date"`
Color string `json:"color"`
}
)