Retreive JSON Keys In Python
My goal is to iterate through every element in classes and add the value of class in classes into a new list. JSON Structure: { 'images': [ { 'classifiers': [
Solution 1:
The first issue is that classifiers
is also a list, so you need an additional index to get at classes
. This will work:
for item in json_data['images'][0]['classifiers'][0]['classes']:
Second, you want the result as a set not a list, so you can do: return set(lst)
. Note that sets are unordered, so don't expect the ordering of items to match that of the list.
Post a Comment for "Retreive JSON Keys In Python"