Created
March 1, 2019 21:18
-
-
Save bbriggs/ff33e8525ac00bac0308a36909112f1d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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