class MessageCreator:
def serialize(self,obj):
return json.dumps(obj,sort_keys=False,indent=None, separators=(',', ':'))
def createGroup(self,name,description,masterkey):
return self.serialize({
'typ':str(types.CREATE_GROUP),
'group':[{
'name':str(name),
'descr':str(description),
'mk':str(masterkey)
}]
})
will return
{"group":[{"mk":"test","name":"test","descr":"test"}],"typ":"517"}
however i want the order to be kept intact like
{"typ":"517","group":[{"name":"test","descr":"test","mk":"test"}]}
How to achieve this?
sort_keys=Trueto ensure a stable key order. It doesn't matter to the consumer of this JSON what the order is, because they are allowed to use any order they like for the keys too.