Reputation: 8796
I have an array of stucts stored a variable my array.
Struct is
type myStruct struct {
id int64 `db:"id" json:"id"`
Name string `form:"name" db:"name" json:"name" binding:"required"`
Status string `form:"status" db:"status" json:"status" binding:"required"`
My array looks like this and is stored in a variable 'myArray'. This array is formed by iterating over a set of rows coming from database.
[{1 abc default} {2 xyz default}]
I am using gin as http server. How do I set this array into JSON reponse using c.JSON. Something like
[
{
id: 1,
name : 'abc'
status: 'default'
},
{
id: 2,
name : 'xyz'
status: 'default'
}
]
Upvotes: 2
Views: 7453
Reputation: 8796
ok c.JSON(http.StatusOK, myArray) worked. But I cannot see the Id field in the response. Any reason why? Is it because of 'int64' dataType?
Upvotes: 4