Protobuf Timestamp field is renamed after conversion to JSON using MessageToJson()

I have a protobuf message that has protobuf Timestamp format as below:

from google.protobuf.timestamp_pb2 import Timestamp

 protoObj = 
   updated {
     seconds: 1631749098
     nanos: 733649969
    }

There is a need to convert it into JSON, but when I convert it into JSON using MessageToJson() as below:

json_msg = MessageToJson(protoObj, preserving_proto_field_name=True)

It gets converted into below

"updated": "2021-06-17T10:27:57.017150"

How can I avoid doing it so? Please help!

Source: Python Questions

LEAVE A COMMENT