arrays - appending non slice to map of slices -
my current code this:
name := "john" id := "1234" c := make(map[string][]string)  c["d"] = make([]string, len(d)) c["l"] = make([]string, len(l))  copy(c["d"], d) copy(c["l"], l) c["test"] = name c["id"] = id   assuming d & l both []string. go not let me this. there way able achieve json this:
{ "name": "john", "id": "1234", "d": [ 123, 456 ], "l": [ 123, 456 ] }
- you need use 
map[string]interface{}instead. - also don't need copy slices.
 
example map[string]interface{}:
name := "john" id := "1234" l, d := []string{"123", "456"}, []string{"789", "987"} c := map[string]interface{}{     "d":    d,     "l":    l,     "test": name,     "id":   id, }        
Comments
Post a Comment