core: Show JSON error offsets where possible (#7437)

This commit is contained in:
Francis Lavoie
2026-01-14 22:54:19 -05:00
committed by GitHub
parent e40bd019ff
commit d269405eab
4 changed files with 18 additions and 4 deletions

View File

@@ -342,7 +342,11 @@ func ParseStructTag(tag string) (map[string]string, error) {
func StrictUnmarshalJSON(data []byte, v any) error {
dec := json.NewDecoder(bytes.NewReader(data))
dec.DisallowUnknownFields()
return dec.Decode(v)
err := dec.Decode(v)
if jsonErr, ok := err.(*json.SyntaxError); ok {
return fmt.Errorf("%w, at offset %d", jsonErr, jsonErr.Offset)
}
return err
}
var JSONRawMessageType = reflect.TypeFor[json.RawMessage]()