-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.

2
  • 1
    @Adrian , isn't that backwards? OP wants to go from an interface{}, not to an interface{} Commented Aug 7, 2017 at 17:54
  • It doesn't matter, the issue is still the same. Commented Aug 7, 2017 at 18:16

1 Answer 1

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]) } } 
Sign up to request clarification or add additional context in comments.

3 Comments

I think this is the only way to go :)
In the first line, var orig [][]interface should read var orig [][]interface{}.
correct, thanks @sebastian

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.