How might I use json_normalize to breakdown a nested JSON object that is contained in a list?
Consider this example:
df = pd.DataFrame({'xd': [
[{
"status": "pass",
"desc": "desc",
"actionable": False,
"err_code": "None",
"err_msg": "None"
}],
[{
"status": "fail",
"desc": "desc",
"actionable": True,
"err_code": "None",
"err_msg": "None"
}] ]})
pd.json_normalize(df['xd']) # not expected
expected = pd.DataFrame({'status': ['pass'],
'desc': ['desc'],
'actionable': False})
# etc..
# expected out
status desc actionable
0 pass desc False
>Solution :
If your json objects are under the xd columns, you can exctract that json, which is a list of dictionaries. A list of dictionaries cand be used to create a dataframe object, from here.
list_of_dicts = list_of_dicts=list(map(lambda l: l[0], df['xd'].to_list()))
expected = pd.Dataframe(list_of_dicts)
Does this answer your question?