I try to return json from my test app. The result returns with quotes and escape characters. How to return raw json?
type Row struct {
Id int `json:"id"`
Value string `json:"value"`
Name string `json:"name"`
}
func GetTestData() map[string]string {
res := map[string]string{}
//db query and other logic
for resultQuery.Next() {
singleRow := Row{}
errorScan := resultQuery.Scan(
&singleRow.Id,
&singleRow.Value,
&singleRow.Name,
)
//error scan here
res[singleRow.Name] = singleRow.Value
}
return res
}
And call this func
g.GET("/test", func(c *gin.Context) {
out, _ := json.Marshal(services.GetTestData())
c.JSON(200, gin.H{"output": string(out)})
})
Query result:
{
"output": "{\"val one\":\"name one\",\"val two\":\"name two\"}"
}
I want to get result like
{
"output": {"val one": "name one", "val two": "name two "}
}
I read about json.RawMessage but can't understand how to implemente it in this case. Thanks everyone!