package main import ( "encoding/json" "fmt" ) // Attributes, eg. Name, must begin with capital letter/character, otherwise it won't work. // Also, JSON mapping is shown. type Message struct { Name string `json:"name"` Body string `json:"body"` Time int64 `json:"unix_time"` } func main() { m := Message{"Alice", "Hello", 1294706395881547000} b, err := json.Marshal(m) fmt.Println(err) fmt.Println(string(b)) }