如何在json中显示映射键和结构的值

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?

So you want a json array instead of a json object?

Instead of loading a map[int]string, why not simply make a []Division?

list := []Division{}
for divisions.Next() {
    var d Division
    err := divisions.Scan(&d.id, &d.name)
    list = append(list, d)
    if err != nil {
        panic(err.Error())
    }
}

You'll need to change the field names to ID and Name so that the json package can serialize them, but you should end up with somthing more like:

[
  {"ID":1,"Name":"Games},
  ...
]