go data_error ai_generated true

rpc error: code = InvalidArgument desc = invalid character '}' looking for beginning of object key string

ID: go/grpc-invalid-argument-malformed-json

Also available as: JSON · Markdown · 中文
80%Fix Rate
86%Confidence
0Evidence
2024-06-28First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.3 active

Root Cause

The request payload is not valid JSON when using a JSON transcoding gateway or custom unmarshal.

generic

中文

使用 JSON 转码网关或自定义反序列化时,请求负载不是有效的 JSON。

Workarounds

  1. 90% success
    if !json.Valid(payload) { return errors.New("invalid JSON") }
  2. 85% success
    import "google.golang.org/protobuf/encoding/protojson"
    // Use protojson.Unmarshal with DiscardUnknown option.

Dead Ends

Common approaches that don't work:

  1. 60% fail

    Printing doesn't fix syntax errors; need proper validation.

  2. 50% fail

    Over-escaping can break valid JSON.