Google.protobuf.json_format.MessageToJson changes field names. How to avoid this?
I have a protocol buffer message object. So I want to serialize it this way:
import json
from google.protobuf.json_format import MessageToJson
with open("file.json", 'w') as fjs:
fjs.write(MessageToJson(message_object))
But it changes the field names of the objects. For example, I had an object like this:
[{
"id": "333333",
"creation_timestamp": 2011,
}]
MessageToJson changed its fields to:
[{
"id": "333333",
"creationTimestamp": "2011",
}]
ie creation_timestamp
changes to creationTimestamp
, and 2011
to "2011"
. How to avoid this?
+1
source to share