So i want to marshal data to JSON. The basic struct looks like this:
type DatabaseObject struct {
Preferences []int `json:"preferences"`
Texts map[string]string `json:"texts"`
Options map[string]string `json:"options"`
Gender string `json:"gender"`
EMail string `json:"email"`
}
Here is the (working) Playground version: https://play.golang.org/p/GI3nAo7L4a
When i use this code in my program however, the result is very different. Here is my code:
jsonObject, err := json.Marshal(DatabaseObject{})
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+v", jsonObject)
It prints:
[123 34 112 114 101 102 101 114 101 110 99 101 115 34 58 110 117 108 108 44 34 116 101 120 116 115 34 58 110 117 108 108 44 34 111 112 116 105 111 110 115 34 58 110 117 108 108 44 34 103 101 110 100 101 114 34 58 34 34 44 34 101 109 97 105 108 34 58 34 34 125]
Does anyone know why json.Marshal does not work here? It's an empty struct, it should look like this
{"preferences":null,"texts":null,"options":null,"gender":"","email":""}