Here is an example: https://play.golang.org/p/aQXJzH6Yjo
i := make(map[string]interface{})
i["some"] = []interface{}{
[]interface{}{1, 2, "3--"},
map[string]interface{}{
"value": "some",
},
}
How can I push additonal value into []interface{}{1, 2, "3--"}
slice? I basically need to create arbitrary datastructure that will be transformed into json. Looked into https://github.com/Jeffail/gabs , but it doesn't seem to allow create nested arrays
It's a little messy, but you can do it as shown here (I've left out the error handling): https://play.golang.org/p/JgZ4fAgRAz
i := make(map[string]interface{})
i["some"] = []interface{}{
[]interface{}{1, 2, "3--"},
map[string]interface{}{
"value": "some",
},
}
fmt.Println(i)
var myval []interface{} = i["some"].([]interface{})
var mylist []interface{} = myval[0].([]interface{})
mylist = append (mylist, "Another value")
// Replace the potentially new slice into element 0
myval[0] = mylist
// No need to write back to the map - the slice is a reference type
fmt.Println(i)