I am trying to convert a nested JSON to a dataframe. The JSON file is deeply nested and I am used the meta parameter to specify the nested structure so that all the JSON attributes can be stored as rows and columns- but I am getting the following error:
TypeError: string indices must be integers
Did i not set the meta parameter properly?
import requests
import pandas as pd
import json
from pandas import json_normalize
requestObject=requests.get("https://dummyjson.com/carts")
#print(requestObject)
requestObject_JSON=requestObject.json()
requestObject_JSON_DF_2=pd.json_normalize(requestObject_JSON,record_path='carts',meta=['id','products'['id','title','price','quantity','total','discountPercentage','discountedPrice'],'total','discountedTotal','userId','totalProducts','totalQuantity'])
print(requestObject_JSON_DF_2)
data =\
{'carts': [{'discountedTotal': 1941,
'id': 1,
'products': [{'discountPercentage': 8.71,
'discountedPrice': 55,
'id': 59,
'price': 20,
'quantity': 3,
'title': 'Spring and summershoes',
'total': 60},
{'discountPercentage': 3.19,
'discountedPrice': 56,
'id': 88,
'price': 29,
'quantity': 2,
'title': 'TC Reusable Silicone Magic Washing Gloves',
'total': 58},
{'discountPercentage': 13.1,
'discountedPrice': 70,
'id': 18,
'price': 40,
'quantity': 2,
'title': 'Oil Free Moisturizer 100ml',
'total': 80},
{'discountPercentage': 17.67,
'discountedPrice': 766,
'id': 95,
'price': 930,
'quantity': 1,
'title': 'Wholesale cargo lashing Belt',
'total': 930},
{'discountPercentage': 17.2,
'discountedPrice': 994,
'id': 39,
'price': 600,
'quantity': 2,
'title': 'Women Sweaters Wool',
'total': 1200}],
'total': 2328,
'totalProducts': 5,
'totalQuantity': 10,
'userId': 97},
{'discountedTotal': 1942,
'id': 2,
'products': [{'discountPercentage': 8.71,
'discountedPrice': 55,
'id': 59,
'price': 20,
'quantity': 3,
'title': 'Spring and summershoes',
'total': 60},
{'discountPercentage': 3.19,
'discountedPrice': 56,
'id': 88,
'price': 29,
'quantity': 2,
'title': 'TC Reusable Silicone Magic Washing Gloves',
'total': 58},
{'discountPercentage': 13.1,
'discountedPrice': 70,
'id': 18,
'price': 40,
'quantity': 2,
'title': 'Oil Free Moisturizer 100ml',
'total': 80},
{'discountPercentage': 17.67,
'discountedPrice': 766,
'id': 95,
'price': 930,
'quantity': 1,
'title': 'Wholesale cargo lashing Belt',
'total': 930},
{'discountPercentage': 17.2,
'discountedPrice': 994,
'id': 39,
'price': 600,
'quantity': 2,
'title': 'Women Sweaters Wool',
'total': 1200}],
'total': 2328,
'totalProducts': 5,
'totalQuantity': 10,
'userId': 98}
]}