I'm trying to find some way to prohibit arbitrary JSON keys and fields in Go. For now, if I send payload with undeclared fields in struct, the service will work normally and will map the entity described fields (likejson:"id,omitempty"
).
For example:
type Foo struct {
Bar int `json:"id,omitempty"`
}
Received JSON:
{
"id": 12,
"hey": "hey"
}
Can anybody help me to find the way of tracking unknown field in payload? I need to return an error in that case.