[Solved] Golang not producing error when decoding “{}” body into struct


{} is just an empty Json object, and it will decode fine to your Operandsstruct, as the struct is not required to have anything in the Operands array.

You need to validate that yourself, e.g.

err := json.NewDecoder(req.Body).Decode(&operands)
if err != nil || len(operands.Values) == 0{

solved Golang not producing error when decoding “{}” body into struct