I have created a simpler version of some JSON data I've been working with here:
[
{
"id": 1,
"city": "Philadelphia",
"Retaillocations": { "subLocation": [
{
"address": "1235 Passyunk Ave",
"district": "South"
},
{
"address": "900 Market St",
"district": "Center City"
},
{
"address": "2300 Roosevelt Blvd",
"district": "North"
}
]
},
"distributionLocations": {"subLocation": [{
"address": "3000 Broad St",
"district": "North"
},
{
"address": "3000 Essington Blvd",
"district": "Cargo City"
},
{
"address": "4300 City Ave",
"district": "West"
}
]
}
}
]
My goal is to normalize this into a data frame (yes, the above json will only create one row, but I am hoping to get the steps down and then generalize it to a larger set).
First, I loaded the file with jsob_obj = json.loads(inputData) which turns this into a dictionary. The problem is that some of the dictionaries can have lists and are nested oddly as shown above. I've tried using pd.json_normalize(json_obj, record_path = 'retailLocations'), I get a type error saying that list indices must be integers or slices, not str. How can I handle the above JSON file and convert it into a single record in a pandas data frame?