-
-
Save zuphzuph/996a5362e7fe60ed286ad9968f83c450 to your computer and use it in GitHub Desktop.
This file contains 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