The other answer is correct. You can also write a helper function to avoid re-merging maps.
// overwriting duplicate keys, you should handle that if there is a need func mergeMaps(maps ...map[string]interface{}) map[string]interface{} { result := make(map[string]interface{}) for _, m := range maps { for k, v := range m { result[k] = v } } return result } func main() { log.Println(`started`) v := []map[string]interface{}{ map[string]interface{}{ `one`: 1, `two`: 2, }, map[string]interface{}{ `one`: `I`, `three`: 3, `other`: `NAN`, }, map[string]interface{}{ `name`: `Bob`, `age`: 300, }, } m := mergeMaps(v...) log.Println(m, len(m)) }
source share