I've this piece of code.
package main
import (
"github.com/gin-gonic/gin"
_ "github.com/go-sql-driver/mysql"
)
func divisionsHandler(c *gin.Context) {
divisions := getDivisionRows()
json := make(map[int]string)
for divisions.Next() {
var d Division
err := divisions.Scan(&d.id, &d.name)
json[d.id] = d.name
if err != nil {
panic(err.Error())
}
}
c.JSON(200, json)
}
The result is
{
1: "games",
2: "technology",
3: "tekk",
4: "home entertainment",
5: "toys & stationery"
}
I am trying to convert that json in something like
{
[{
"id": 1,
"name": "games"
},
...
]
}
but how?