This is a creation in Article, where the information may have evolved or changed.
Code Source: Http://stackoverflow.com/questions/19991541/dumping-mysql-tables-to-json-with-golang
func Getjson (SqlString String) (string, error) {stmt, err: = db. Prepare (sqlString) if err! = Nil {return nil, Err}defer stmt. Close () rows, err: = stmt. Query () if err! = Nil {return nil, err}defer rows. Close () columns, err: = rows. Columns () if err! = Nil {return "", Err}count: = Len (Columns) Tabledata: = Make ([]map[string]interface{}, 0) values: = Make ([]interface{}, Count) Valueptrs: = Make ([]interface{}, Count) for rows. Next () {for i: = 0; i < count; i++ {valueptrs[i] = &values[i]} rows. Scan (Valueptrs ...) Entry: = Make (map[string]interface{}) for I, col: = range columns {var v interface{} val: = Values[i] B, OK: = val. ([ ]byte) If ok {v = string (b)} else {v = val} Entry[col] = v} tabledata = Append (tabledata, entry)}jsondata, er r: = json. Marshal (tabledata) if err! = Nil {return "", err}fmt. Println (String (jsondata)) return string (Jsondata), nil}