If you have the following JSON structure:
[
{
"type": "home",
"name": "house #1",
... some number of properties for home #1
},
{
"type": "bike",
"name": "trek bike #1",
... some number of properties for bike #1
},
{
"type": "home",
"name": "house #2",
... some number of properties for home #2
}
]
How do you decode this in Golang to a struct without knowing what each type is until you unmarshall the object. It seems like you would have to do this unmarshalling twice.
Also from what I can tell, I should probably be using the RawMessage to delay the decoding. But I am not sure how this would look.
Say I had the following structs:
type HomeType struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Bathrooms string `json:"bathrooms,omitempty"`
... more properties that are unique to a home
}
type BikeType struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Tires string `json:"tires,omitempty"`
... more properties that are unique to a bike
}
Second question. Is it possible to do this in streaming mode? For when this array is really large?
Thanks