For example:
{["NewYork",123]}
For json array is decoded as a go array, and go array is need to explicit define a type, I don't know How to deal with it.
First that json is invalid, objects has to have keys, so it should be something like {"key":["NewYork",123]}
or just ["NewYork",123]
.
And when you're dealing with multiple random types, you just use interface{}
.
const j = `{"NYC": ["NewYork",123]}`
type UntypedJson map[string][]interface{}
func main() {
ut := UntypedJson{}
fmt.Println(json.Unmarshal([]byte(j), &ut))
fmt.Printf("%#v", ut)
}
playground
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With