I'm trying to store API output into CSV/db and can not figure out how I can make for those Key in "tierList". One row in my case should be on bin and I need key as a columns in my output.
Is it possible to do with pd.JSON_Normalize ? Please direct me to the right lib/tool.
Thanks to all.
Please refer to compact test python script below. I don't understand why I can only use record_path='memberList. Anything else gives an error. According all theory I should be able to use record_path=memberRiskData and add rest of columns with meta.
import json
import os
import pandas as pd
json_file = '''
{ "content":"BIN REST", "riskMonth":"20250401", "pagination":{ "currentPage":1, "totalPages":26 },
"memberList":[
{ "bin":"22222","firstName":"MARIA", "lastName":"PLACARD",
"memberRiskData":{
"strata":"East", "postParameter":"",
"tierList":[
{ "riskTier":"AdverseSubdomainTier",
"tierValue":"High" },
{ "riskTier":"SocialDomainTier",
"tierValue":"Med" } ] } } ]} '''
data = json.loads(json_file)
print('.......type =',type(data))
print(data.items())
print(data['memberList'][0])
df = pd.json_normalize(data, record_path='memberList') # , meta=['strata','content']) TBD....
print (df)
df.to_csv('c:/out.csv', index=False)
My current output is below. Somehow I need to break column memberRiskData.tierList into few for each key.

