js = {"Alex":{"b_":{"ep_0":"[1,2,3]"}, "g_":{"ep_0":"[3,4,5]"}, "f_":{"ep_0":"[3,4,5]", "ep_1":"[3,4,5]"}},
"Sam":{"b_":{"ep_0":"[1,2,3]"}, "g_":{"ep_0":"[3,4,5]"}},
"Joe":{"b_":{"ep_0":"[1,2,3]"}, "g_":{"ep_0":"[3,4,5]"}, "f_":{"ep_1":"[31,44,56]"}}
}
I need to read ep_0 and ep_1 for each user, here is my snipped code:
users = [i for i in js.keys()]
data = {}
final_data = {}
for key in users:
for user in js[key].keys():
if 'f_' not in key:
continue
for z in js[users]['f_']:
if 'ep_0' not in z:
continue
data['ep0'] = js[user]['f_']['ep_0']
if 'ep_1' not in z:
continue
data['ep1'] = js[user]['f_']['ep_1']
final_data[user] = data
print(final_data)
the output of my code is {} and desire output should be:
{'Alex': {'f_':{'ep_0':'[3,4,5]', 'ep_1':'[3,4,5]'}}, 'Joe': { 'f_':{'ep_1':'[31,44,56]'}} }
print()in different places to see values in variables - this helps you to see where is the problem..items().js = ...is assigning a Python data structure; to be JSON, it would need to have double quotes -- unless you're referring to the lists in the inner strings being JSON?