title: How to Convert JSON to CSV?
body: <p>How can I fix the error?</p>
  
  <p><a href="http://play.golang.org/p/0UMnUZOUHw" rel="noreferrer">http://play.golang.org/p/0UMnUZOUHw</a></p>
  
  <pre><code>// JSON to CSV in Golang
  package main
  
  import (
      "encoding/csv"
      "encoding/json"
      "fmt"
      "io/ioutil"
      "os"
  )
  
  type Json struct {
      RecordID int64  `json:"recordId"`
      DOJ      string `json:"Date of joining"`
      EmpID    string `json:"Employee ID"`
  }
  
  func main() {
      // reading data from JSON File
      data, err := ioutil.ReadFile("./people.json")
      if err != nil {
          fmt.Println(err)
      }
      // Unmarshal JSON data
      var d []Json
      err = json.Unmarshal([]byte(data), &amp;d)
      if err != nil {
          fmt.Println(err)
      }
      // Create a csv file
      f, _ := os.Create("./people.csv")
      defer f.Close()
      // Write Unmarshaled json data to CSV file
      w := csv.NewWriter(f)
  
      // How to proceed further?
      /* I am getting errors if i use below
      for _,obj := range d {
        var record []interface{}
        record = append(record, obj.RecordID)
        record = append(record, obj.DOJ)
        record = append(record, obj.EmpID)
        w.Write(record)
      }
      */
  }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>cannot use record (type []interface {}) as type []string in function argument
  </code></pre>