Loop through JSON to get value - Python

Viewed 33

I'm trying to loop over JSON to get values and declare it to variables and append it to dateframe to unique id. I tried few solutions, but in every I didn't achive what I want. Excuse me for my English and I just wanted to tell that I'm new in Python

  1. In this example when i dont have value in this root I have duplicates, but I want to get empty value.
for index, row in df.iterrows():
    attribute = json.loads(row['attribute'])
    try:
        for i in range (0,5):
            Example= attribute['0'][i]['attributes_1']
            adress= Example.get('adress', '')
    except:
        adress = ''
  1. In this example when I check row it looks like it pasted, but it just doesnt want to add to my dataframe.
for index, row in df.iterrows():
    jsn = json.loads(row['attribute'])

    for i in range(0,  5):
        try:
            path= jsn['0'][i]['attributes_1']
            row['example'] = path.get('example', '')
        except:
            ''
0 Answers
Related