Python json.loads changes the order of the object

Dictionaries (objects) in python have no guaranteed order. So when parsed into a dict, the order is lost.

If the order is important for some reason, you can have json.loads use an OrderedDict instead, which is like a dict, but the order of keys is saved.

from collections import OrderedDict

data_content = json.loads(input_data.decode('utf-8'), object_pairs_hook=OrderedDict)

Leave a Comment