That's the expected behaviour of
Decode (as documented in the
By default, object keys which don't have a corresponding struct field are ignored.
You can however use the
DisallowUnknownFields() function (as described in the docs as well) to have it fail if the input JSON has fields not contained in the destination struct.
dec := json.NewDecoder(r) dec.DisallowUnknownFields()
In that case, you'll get an error as you expect.
Modified playground here: https://play.golang.org/p/A0f6dxTXV34