I have a json file which I'm reading as a json object and looping over the object. The json object is a list of dictionaries, which has the following structure.
[{
"ACT": "235",
"Unit": "ABG",
"Center": "West",
"web": "160",
"Env": "QA",
"Ret": "30",
"Int": "2",
"All": "BU",
"SRV": "Std",
"Type": "none"
}, {
"ACT": "178",
"Unit": "GHu",
"Center": "West",
"web": "198",
"Env": "PE",
"Ret": "30",
"Int": "3",
"All": "BU",
"SRV": "Std",
"Type": "none"
}, {
"ACT": "167",
"Unit": "orp",
"Center": "East",
"web": "190",
"Env": "PD",
"Ret": "30",
"Int": "1",
"All": "BU",
"SRV": "Std",
"Type": "none"
}]
Following is my code to loop over the json object
import json
import sys
ref_data = json.load(open('roche_test.json'))
json_len = len(ref_data)
i = 0
j = 0
for i in range(0,json_len):
for j in range (0,len(ref_data[i])):
print ref_data[i].values()[j]
It's looping through all dictionaries in order, however the looping over each dictionary is jumbled.
Eg : print ref_data[0].values()[3]
will output 2
and print ref_data[0].keys()[3]
will output Int
whereas it should have been outputing 160 and web.
Any inputs on why this might be happening?