I am requesting an API which returns JSON containing an array of objects. The problem is that the objects can take two forms. They can either be a string or an object. An example result could look like this:
[
{"name": "obj1", "key2": ["a", "b"]},
"obj2",
{"name": "obj3"}
]
A string element "objX"
is equivalent to {"name": "objX"}
.
I want to parse this into a slice of the following type:
type Obj struct {
Name string
Key2 []string
}
How do I do this in a reasonable fashion?