I need to generate a MD5 Hash in Python 3 to compare with a MD5 Hash that was generated on Python 2, but the result for json.dumps() is different, because on Python 2 the position of the elements changes and the MD5 result is different.
How can I generate the same result?
The code:
content = {'name': 'Marcelo', 'age': 30, 'address': {'country': 'Brasil'}, 'interests': [{'id': 1, 'description': 'tecnology'}]}
print('CONTENT:', json.dumps(content))
print('MD5:', md5(str(content).encode('UTF-8')).hexdigest())
The Python 2.7 result:
('CONTENT:', {'interests': [{'id': 1, 'description': 'tecnology'}], 'age': 30, 'name': 'Marcelo', 'address': {'country': 'Brasil'}})
('MD5:', 'a396f6997fb420992d96b37e8f37938d')
The Python 3.6 result:
CONTENT: {'name': 'Marcelo', 'age': 30, 'address': {'country': 'Brasil'}, 'interests': [{'id': 1, 'description': 'tecnology'}]}
MD5: 40c601152725654148811749d9fc8878
Edit:
I can't change the MD5 generated on Python 2. There is any way to reproduce the default order from Python 2 on Python 3?