Hy guys. Once defining on a proto message field a tag as

message Some {
   string    ref = 4 [json_name = "$ref"]; 
}

it actually generates such output golang code

    Ref   string    `protobuf:"bytes,4,opt,name=ref,json=$ref,proto3" json:"ref,omitempty"`       

which is inconsistent in regard of json name for protobuf and json tags so for json.Marshal and json.Unmarshal it doesn't follow the intended behavior.

So my questions are 1. how actually to set the tags consistently for both tags 2. what are the intention for protobuf to have a standalone declaration for json. What is the way to see its effect. And what might be the real case for having two different behaviors for json.Marshal / Unmarshal and that special case approach.

Thank you.

Comment From: puellanivis

The json_name option is a protobuf feature. For Historical Reasons, we cannot change the json:"name" like you can override with json_name.

You should be using the protojson package for marshalling and unmarshalling JSON though. The older json tags were an idiosyncratic feature of the golang protobuf package, and is not at all supported by any other language.

Comment From: puellanivis

Oh, more info in this issue, for which this seems to be a duplicate: https://github.com/golang/protobuf/issues/1388