This question already has an answer here:
Is there any easy way to convert [][] interface{}
to [][]string
? What I want is to to write this [][] interface{}
to a csv
but writer
in go
accepts only [][]string
. Additional info : my [][] interface{}
contains 4 columns 2 of them are string and 2 are json.Number
.
Thanks in advance.
</div>
Simplest way is probably to make new slices and write some loops:
var orig [][]interface{}
var strs = make([][]string, len(orig))
for i := range orig {
strs[i] = make([]string, len(orig[i]))
for j := range orig[i]{
strs[i][j] = fmt.Sprint(orig[i][j])
}
}