I believe you can annotate the struct field using syntax similar to: status string `json:"statusCode"`
for example. - D On Mon, Nov 15, 2021 at 3:52 PM Josh Morehead <[email protected]> wrote: > I am wondering if there is a way to map a JSON field to a Go struct field > of a different name?? > > For instance... can I put in my .proto an object with the field `status` > and have that map to a JSON field of `statusCode`?? This way when I > unmarshal the JSON the value at `statusCode` would appear in the Go struct > field `status`. > > The only place I know to control that would be in the declaration of the > struct housing the field... but in this case that is autogenerated code > which appears to use the .proto field to create the mapped JSON field. Any > help would be much appreciated. > > -- > You received this message because you are subscribed to the Google Groups > "Protocol Buffers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/protobuf/80d8024a-90ce-4dda-9a27-8839e332096dn%40googlegroups.com > <https://groups.google.com/d/msgid/protobuf/80d8024a-90ce-4dda-9a27-8839e332096dn%40googlegroups.com?utm_medium=email&utm_source=footer> > . > On Mon, Nov 15, 2021 at 3:52 PM Josh Morehead <[email protected]> wrote: > I am wondering if there is a way to map a JSON field to a Go struct field > of a different name?? > > For instance... can I put in my .proto an object with the field `status` > and have that map to a JSON field of `statusCode`?? This way when I > unmarshal the JSON the value at `statusCode` would appear in the Go struct > field `status`. > > The only place I know to control that would be in the declaration of the > struct housing the field... but in this case that is autogenerated code > which appears to use the .proto field to create the mapped JSON field. Any > help would be much appreciated. > > -- > You received this message because you are subscribed to the Google Groups > "Protocol Buffers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/protobuf/80d8024a-90ce-4dda-9a27-8839e332096dn%40googlegroups.com > <https://groups.google.com/d/msgid/protobuf/80d8024a-90ce-4dda-9a27-8839e332096dn%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/CAJGs%2BiJm%3DZAoSyPsOhZd6%3DR4%3DUQnkq9BPq%2B0F6zi3XxauCom9w%40mail.gmail.com.
