Skip to content

Instantly share code, notes, and snippets.

@zuphzuph
Forked from bbriggs/aws_ec2_to_json.go
Created March 1, 2019 22:32
Show Gist options
  • Save zuphzuph/996a5362e7fe60ed286ad9968f83c450 to your computer and use it in GitHub Desktop.
Save zuphzuph/996a5362e7fe60ed286ad9968f83c450 to your computer and use it in GitHub Desktop.
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