Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package main
import (
"encoding/csv"
"encoding/json"
"io/ioutil"
"os"
)
type Instance struct {
InstanceId string `json:"InstanceId"`
Name string `json:"Name"`
}
func main() {
data, err := ioutil.ReadFile("./instances.json")
if err != nil {
panic(err)
}
var instances []Instance
err = json.Unmarshal([]byte(data), &instances)
if err != nil {
panic(err)
}
f, err := os.Create("./instances.csv")
if err != nil {
panic(err)
}
defer f.Close()
w := csv.NewWriter(f)
for _, v := range instances {
var entry []string
entry = append(entry, v.Name, v.InstanceId)
w.Write(entry)
}
w.Flush()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.