Skip to content

Instantly share code, notes, and snippets.

@brettski
Created August 20, 2018 19:53
Show Gist options
  • Save brettski/a3ea3b992cfa1c81e3ab37fe22ebaa69 to your computer and use it in GitHub Desktop.
Save brettski/a3ea3b992cfa1c81e3ab37fe22ebaa69 to your computer and use it in GitHub Desktop.
Create json string in golang
// You can edit this code!
// Click here and start typing.
package main
import (
"fmt"
"encoding/json"
)
func main() {
type Message struct {
Name string
Body string
Time int64
}
m := Message{"Alice", "Hello", 1294706395881547000}
b, err := json.Marshal(m)
if err != nil {
fmt.Println(err)
return
}
//b == []byte(`{"Name":"Alice","Body":"Hello","Time":1294706395881547000}`)
fmt.Println(string(b))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment