I am trying to convert a SQL Output (GORP) to JSON. I am using gorp with mySql.
Here is my selected code
type Mane struct {
ManeId string `db:"mane_id"`
Manetana string `db:"manetana"`
Yajamana string `db:"yajamana"`
}
var manegalu []Mane
_, err = dbmap.Select(&manegalu, "SELECT mane_id, manetana, yajamana FROM kd_mane")
//Option 1: Not working: Array of numbers. Not the actual json
a, err := json.Marshal(manegalu)
mt.Fprint(w, string(a))
//Option 2: Not working: Array of numbers. Not the actual json
for _, p := range manegalu {
a, err := json.Marshal(p)
fmt.Fprint(w, string(a))
}
I am expecting and output like this
{"mane_id":3323, "manetana":"ABC", "yajamana":"hgy"},{"mane_id":2323, "manetana":"ADFC", "yajamana":"FDER"},{"mane_id":12343, "manetana":"GDSC", "yajamana":"hFDEy"}
Can you please let me know what am I doing wrong? I understand that why option 1 does not work. But option 2 seems good for me as per https://gobyexample.com/json
Got it done.