An API I query returns a JSON where one of the elements should be an array but is wrapped in quotation marks. It seems therefore the "encoding/json" package doesn´t recognize that element as an array.
When I try to make that element accessible as a map I get the error:
interface conversion: interface is string, not []interface {}
Playground: https://play.golang.org/p/K1H01q-Dqc
package main
import (
"fmt"
"encoding/json"
)
func check(e error) {
if e != nil {
panic(e)
}
}
var incomingJson string = `{
"status":"success",
"content":"[{\"id\":\"567670128\"},{\"id\":\"567670129\"}]"
}`
func main() {
// Decode incoming json
var encodedJson map[string]interface{}
err := json.Unmarshal([]byte(incomingJson), &encodedJson)
check(err)
fmt.Println(encodedJson)
// Accessing "content" data
contentOjects := encodedJson["content"].([]interface{})
contentObject0 := contentOjects[0].(map[string]string)
fmt.Println(contentObject0)
}
How should I convert/cast the string in ["content"]
so I can parse it into map[string]string
?