Skip to content

Instantly share code, notes, and snippets.

@geraldstanje
Created October 5, 2014 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geraldstanje/cfaf6919ccae6fbf2744 to your computer and use it in GitHub Desktop.
Save geraldstanje/cfaf6919ccae6fbf2744 to your computer and use it in GitHub Desktop.
golang json encoding
package main
import "encoding/json"
import "fmt"
import "bytes"
type tableEntry struct {
Name string
Age string
Gender string
}
func main() {
t := tableEntry{"Person", "10", "Male"}
jsonData, err := json.Marshal(t)
if err != nil {
fmt.Println("json encoding error")
}
var b bytes.Buffer
b.Write(jsonData)
fmt.Print(b.String())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment