'Unmarshal array of empty interface pointer `*[]interface{}`

I have a JSON file in which the value of each key also contains JSON data. So I have tried to work with the toplevel keys in the main file and tried work and parse the nested data structure to some other go files.

main.go

//Unmarshal the main json
var data map[string][]interface{}
json.Unmarshal(someByte, data)

//Sending the value to be parsed in a different file if necessary
var key1 = Mdata["key1"]
NewKey1StructType().GetMethod(&key1)

key1.go

// type and constructor
type Key1Struct struct {
}
func NewKey1StructType() *Key1Struct {
    return &Key1Struct{}
}
//GetMethod
//type that has the structure of the value of key1
type ValueType stuct {
 val1 string `json: ......`
......
}
func (s Key1Struct) GetMethod(i *[]interface{}) {
    var m ValueType
    json.Unmarshal(i, &m)
// ................| <- It expects []byte instead of *[]interface{}

data.json

{
   "key1" : [ {"key1a":"value1a"},{"key1b":"value1b"} ],
   "key2" : {"key2a":"value2a"} ,
   ........
   "keyN" : [{"keyNa":"valueNa"},{"keyNb":"valueNb"}]
}

Where,

  • string = key1
  • []interface{} = [{"keyNa":"valueNa"},{"keyNb":"valueNb"}]

How can I unmarshal *[]interface{} in this kind of situation?

go


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source