It looks like it contains a single field. What would you expect as user value ?
It could be that models.User has only unexported fields (name not starting with an upercase letter), or the structure definition is missing the json tags.
So it has both problems to be used as json output.
The json decoder only consider exported struct field name. A field name is exported when its first lette is in uppercase.
Since the field names in the JSON encoded data are often lowercase, we have to specify the mapping of the json field name and the structure field name. This is done by using tags. Tags are strings enclosed in backticks and placed at the right of the field definition.
Here is how you should define the models.User struct.
type User struct {
ID int `json:id`
FirstName string `json:firstName`
LastName string `json:lastName`
Password string `json:password`
}
The value after json: is the field name in the json encoded data. If you did gave us an example of JSON encoded data, I would be sure what value should be put there. I assumed that these are the field names in the json encoded data.
Note that if you can’t modify models.User because it is from a package you can’t or should not modify, you should than use an intermediate structure with the above definition, decode the JSON data in it, and then copy each field value in the models.User structure.
This intermediate structure is a frequently used pattern.