Here I have message a map interface. There are 2 keys in it key1, key2. Key2 has 2 keys k2, k3. I want to add another key in it. So I did this.
message := map[string]interface{}{
"key1": map[string]string{
"k1" : "",
},
"key2": map[string]interface{}{
"k2": "",
"k3" : map[string]interface{}{
"kk1" : "",
},
},
}
k := map[string]interface{}{
"kk2" : "",
}
message["key2"]["k4"] = k
b, err := json.Marshal(message)
if err != nil {
fmt.Println(err)
}
fmt.Println(string(b))
But I am getting error as:
message["key2"]["k4"] (type interface {} does not support indexing)