I am trying to convert my struct "Sim" into JSON, after being filled with data.
When I print the var s, it shows correct information, when I print data, it shows blank.
How do I convert Struct to JSON?
Reduced Code Below:
type Sim struct { yr, ag, av, db, wd, st []int withdrawal []string } func main() { // Creating simulation var s Sim // Filling with data s = simulate(15000, 60, 65, 90, 2015, 10.0, 140000.0, true, s) // Converting to JSON, for transmission over web data, err := json.Marshal(s) if err != nil { fmt.Println(err) return } // Data is correct fmt.Println(s) // Prints: {} fmt.Println(string(data)) }