go data_error ai_generated true

proto: JSON 中字段 "name" 重复

proto: duplicate field "name" in JSON

ID: go/protobuf-json-marshal-duplicate-field

其他格式: JSON · Markdown 中文 · English
80%修复率
85%置信度
0证据数
2025-06-20首次发现

版本兼容性

版本状态引入弃用备注
1.x active — — —

根因分析

JSON 输入中同一字段出现多次,protojson 拒绝解析。

English

The JSON input contains the same field more than once, which protojson rejects.

generic

解决方案

  1. 90% 成功率
    // Validate JSON before sending; use a library that enforces uniqueness.
  2. 85% 成功率
    opts := protojson.UnmarshalOptions{DiscardUnknown: true}
    err := opts.Unmarshal(data, msg)

无效尝试

常见但无效的做法:

  1. 80% 失败

    Lenient parsers may not handle protobuf semantics correctly.

  2. 70% 失败

    Manual removal is error-prone and not scalable.