-1

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.

Mohammed
  • 637
  • 13
  • 26

1 Answers1

3

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])
   }
}
captncraig
  • 22,118
  • 17
  • 108
  • 151