Hey all,
One thing that frustrated me when working with envoy grpc to json transcoding is that the field order in the output json message was decided using the tag numbers of the protobuf fields.
This is a bit problematic in cases where you want to make your json's more human readable - when adding fields that are expected to be located one near the other (think many fields, or even oneofs!) - tags are not meant to be changed, and order of fields in proto file can be freely changed, but json outputs can not. Changing tag values for this - is not an acceptable solution.
I tracked the issue down to the protobuf C library.
I suggest adding a new json print option:
preserve_descriptor_field_order
By default it will be false - so no behaviour change, but when true - fields will be ordered like in the descriptor (believe it or not, this is actually the default behavior, but then there is an explicit sort - using tag numbers!).
Added a test to showcase the feature.
See my PR, for all the details:
https://github.com/protocolbuffers/protobuf/pull/19152