Skip to content

Instantly share code, notes, and snippets.

@sammachin
Created Aug 7, 2014
Embed
What would you like to do?
Parse JSON STAT
#First we create an empty dict object
data = {}
#We need to specify the dataset name
dataset = "QS104EW"
# We get the actaul observation values from the JSON-STAT as a list
values = obj[dataset]['value']
# Then we get the index of the observations and its asccociated categories as a dict
index = obj[dataset]['dimension'][obj[dataset]['dimension']['id'][1]]['category']['index']
#and finally the labels for the categories as another dict
labels = obj[dataset]['dimension'][obj[dataset]['dimension']['id'][1]]['category']['label']
for l in labels: #Now we can iterate through the labels
num = index[l] # get the position in the values dict of the specific label
count = values[str(num)] #get that value from the values list
data[labels[l]] = count #create a new object in data dict for the value with the label as its name
print data #All done!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment