StrictUnmarshalJSON is like json.Unmarshal but returns an error if any of the fields are unrecognized. Useful when decoding module configurations, where you want to be more sure they're correct.
(data []byte, v any)
| 340 | // module configurations, where you want to be more sure they're |
| 341 | // correct. |
| 342 | func StrictUnmarshalJSON(data []byte, v any) error { |
| 343 | dec := json.NewDecoder(bytes.NewReader(data)) |
| 344 | dec.DisallowUnknownFields() |
| 345 | err := dec.Decode(v) |
| 346 | if jsonErr, ok := err.(*json.SyntaxError); ok { |
| 347 | return fmt.Errorf("%w, at offset %d", jsonErr, jsonErr.Offset) |
| 348 | } |
| 349 | return err |
| 350 | } |
| 351 | |
| 352 | var JSONRawMessageType = reflect.TypeFor[json.RawMessage]() |
| 353 |
no outgoing calls
no test coverage detected