title: How to save a JSON file into csv
body: <p>I am trying to save this astros.json file into csv file.</p>
  
  <p>Everything is working I don't have any error but my code is not going into my <code>for</code> loop.</p>
  
  <p>So the astros.csv file is created successfully but there are no datas inside.</p>
  
  <pre><code>package main
  
  import (
      "encoding/json"
      "encoding/csv"
      "fmt"
      "io/ioutil"
      "os"
      "net/http"
      "strconv"
  )
  
  type People struct {
      Name string
      Craft string
  }
  
  type General struct {
      //People []People
      Number int
      Message string
  }
  
  func main() {
      // Reading data from JSON File  
      response, err := http.Get("http://api.open-notify.org/astros.json")
      if err != nil {
          fmt.Printf("The Http request failed with error %s\n", err)
      }
  
      data,_ := ioutil.ReadAll(response.Body)
      //fmt.Println(string(data))
      // Unmarshal JSON data
      var general []General
      json.Unmarshal([]byte(data), &amp;general)
      //fmt.Printf("First person: %s, Message: %s", general.People[0].Name, general.Message)
  
      // Create a csv file
      csvdatafile, err := os.Create("./astros.csv")
      if err != nil {
          fmt.Println(err)
      }
      defer csvdatafile.Close()
      // Write Unmarshaled json data to CSV file
      w := csv.NewWriter(csvdatafile)
      for _, obj := range general {   
          fmt.Println("Are you going into the for ?")
          var record []string
          //record = append(record, obj.People)
          record = append(record, strconv.Itoa(obj.Number), obj.Message)
          record = append(record, obj.Message)
          //record = append(record, []string{People})
          w.Write(record)
          fmt.Println("Are you coming here")
          record = nil
      }
      w.Flush()
      fmt.Println("Appending succed")
  
  }
  </code></pre>