5👍
✅
Python dict is unordered, so you loose the order of your initial data.
The workaround is to use OrderedDict
from built-in collections
module:
import json
import collections
ordered_json = json.loads(your_json_string, object_pairs_hook=collections.OrderedDict)
More documentation about OrderedDict here.
Source:stackexchange.com