Different behavior of json.dump() on Windows and Linux

Viewed 1474

I wrote a python script to retrieve data from a website in json format using the requests library, and then I dump it into a json file. I have written a lot of code utilizing this data and have tested it in Windows only. Recently I shifted to a Linux system, and when the same python script is executed, the order of the keys in the json file is completely different.

This is the code I'm using:

API_request = requests.get('https://www.abcd.com/datarequest')
                    alertJson_Data = API_request.json()         # To convert returned data to json
json.dump(alertJson_Data, jsonDataFile)     # for adding the json data for the alert to the file
jsonDataFile.write('\n')
jsonDataFile.close()

A lot of my other scripts depends on the ordering of the keys in this json file, so is there any way to maintain the same ordering that is used in Windows to be used in Linux as well? For example in Windows the order is "id":, "src":, "dest":, whereas in Linux its completely different. If I directly go to the Web link on my browser, it has the same ordering as the one saved in Windows. How do I retain this ordering?

1 Answers
Related