I am using the 'json' packages to read JSON files and convert to CSV. I wrote a script some months ago using Python 2.7, which extracts a dictionary containing the name of the objects in JSON file (It worked perfectly back then). When I run the script in Python 3.3 the order in which the objects are retrieved are different every time the script is executed.
Any idea why this happens? and How to fix it?
My script:
import json
import csv
input_file = open('my_path\\json_file', 'r')
myjson = json.load(input_f)
input_f.close()
new_json = myjson['markers'] #main object containing sub-objects
keys = {} #empty dictionary to store list of sub-objects
for i in new_json:
for k in i.keys():
keys[k] = 1
Some output examples:
EXECUTION 1:
KEYS{'': 1, 'latitude': 1, 'Particles': 1, 'Wind Speed': 1, 'image': 1, 'Humidity': 1, 'C/ Daoiz y Velarde': 1, 'Noise': 1, 'Battery level': 1, 'id': 1, 'Soil Moisture': 1, ....}
EXECUTION 2:
KEYS{'': 1, 'Relative humidity': 1, 'N02': 1, 'Particles': 1, 'Rainfall': 1, 'image': 1, 'Odometer': 1, 'Co Index': 1, 'Wind Direction': 1, 'Atmospheric Pressure': 1, ....}