Created
August 20, 2018 19:53
-
-
Save brettski/a3ea3b992cfa1c81e3ab37fe22ebaa69 to your computer and use it in GitHub Desktop.
Create json string in golang
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
// 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