How to add square brackets in JSON object with python
问题 I just need contexts to be an Array ie., 'contexts' :[{}] instead of 'contexts':{} Below is my python code which helps in converting python data-frame to required JSON format This is the sample df for one row name type aim context xxx xxx specs 67646546 United States of America data = {'entities':[]} for key,grp in df.groupby('name'): for idx, row in grp.iterrows(): temp_dict_alpha = {'name':key,'type':row['type'],'data' :{'contexts':{'attributes':{},'context':{'dcountry':row['dcountry']}}}}