Skip to content

Instantly share code, notes, and snippets.

@EtienneR
Last active August 29, 2015 14:27
Show Gist options
  • Save EtienneR/5c4344043abe1bb87f91 to your computer and use it in GitHub Desktop.
Save EtienneR/5c4344043abe1bb87f91 to your computer and use it in GitHub Desktop.
JSON export file with Go (via io/ioutil)
{"name":"this is the name value","description":"this is the description value","email":"this is the email value"}
package main
import (
"encoding/json"
"io/ioutil"
)
// JSON struct
type Conf struct {
Name string `json:"name"`
Description string `json:"description"`
Email string `json:"email"`
}
func main() {
// Values data
data := Conf{"this is the name value", "this is the description value", "this is the email value"}
// Transform to JSON (bytes format)
content, err := json.Marshal(data)
if err != nil {
panic(err)
}
// Write in a file (or existing ecrase)
err = ioutil.WriteFile("foo.json", content, 0644)
if err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment