I'm getting an error of:
json.Unmarshal undefined (type interface {} has no field or method Unmarshal)
trying to convert a json byte slice into the generic interface{} type. I'm reading the docs for encoding/json
and they give an example that shows this is valid. What gives?
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
)
func main() {
var json interface{}
data, _ := ioutil.ReadFile("testMusic.json")
json.Unmarshal(data, &json)
m := json.(map[string]interface{})
fmt.Printf("%+v", m)
}
You've defined a local variable json
that masks the global symbol json
referring to the JSON module. Renaming your local variable should allow your code to work.