gorm db.find(&users) to json with gin in golang

7.2k views Asked by At

This is my GET Method the problem is that all i get in the json is one user instead there are 3 users in my database.

func GetUsers(c *gin.Context) {

var users = db.Find(&models.Person{})
c.JSON(200, users)
}
1

There are 1 answers

0
Evan Grayson On BEST ANSWER

Try this:

func GetUsers(c *gin.Context) {
 users := []models.Person{}
 db.Find(&users)
 c.JSON(200, &users)
}