I've been using
json.NewDecoder()
err = decoder.Decode(&m)
to decode JSON and map into a custom struct. When I made a request with another JSON, decoder doesn't return an error. I used required for binding but It didn't change anything.
My custom struct looks like this
type UpdateUserInformationModel struct {
Token string `json:"Token" binding:"required"`
Name string `json:"Name" binding:"required"`
Lastname string `json:"Lastname" binding:"required"`
PhoneNumber string
ProfilePhotoInBase64String string
AdditionalInformation string
}
I made a request with this JSON
{
"Token":"CHlBciGyuTsJ1B5JYLjT",
"Name":"Mert"
}
and decoder doesn't return an error. Can anyone help me?
When I searched the net for the answer doing it manually. Do we have another option for checking if field exist on JSON automatically.