Re: [go-nuts] json.Unmarshal with disallowUnknownFields

2020-07-30 Thread Brian Candler
Sure, I now have this as a drop-in replacement for json.Unmarshal: func StrictUnmarshal(data []byte, v interface{}) error { dec := json.NewDecoder(bytes.NewReader(data)) dec.DisallowUnknownFields() return dec.Decode(v) } I just wondered if I was missing something. -- You received this message b

Re: [go-nuts] json.Unmarshal with disallowUnknownFields

2020-07-30 Thread roger peppe
You could write a function to do that for you. On Thu, 30 Jul 2020, 09:45 Brian Candler, wrote: > I want to do a json.Unmarshal of []byte data whilst also getting the > disallowUnknownFields behaviour. Is there any tidier way than this > ? > > dec := json.

[go-nuts] json.Unmarshal with disallowUnknownFields

2020-07-30 Thread Brian Candler
I want to do a json.Unmarshal of []byte data whilst also getting the disallowUnknownFields behaviour. Is there any tidier way than this ? dec := json.NewDecoder(bytes.NewReader(data)) dec.DisallowUnknownFields() var v mystruct err := dec.Decode(&v) -- Yo