My json data looks like this:
[
{
"fields": {
"bkdate": null,
"business_credit_card_total_balances": null,
"business_credit_card_total_limits": null,
"business_total_monthly_debt_payments": null,
"business_total_mortgage_monthly_payments": null,
"created_at": "2016-08-04T00:29:03.067Z",
"detail_results": null,
"error_reason": "no reasons",
"fico_v2": "695",
"fico_v3": null,
"loanapp_id": 194,
"personal_credit_card_total_balances": null,
"personal_credit_card_total_limits": null,
"personal_total_monthly_payments": null,
"report_type": "CreditProfile",
"result": true,
"role": "applicant",
"total_mortgage_monthly_payments": null,
"username": "cho",
"version": "CF Microloan",
"xml_data": "<?xml version=\"1.0\" standalone=\"no\"?><NetConnectResponse xmlns=\"http://www.experian.com/NetConnectResponse\"><CompletionCode>0000</CompletionCode>"
},
"model": "common.prequalresult",
"pk": 1
}
]
I Want to convert it into SQL table. I tried this:
v = pd.DataFrame(data['fields'])
t = pd.io.json.json_normalize(data['fields'], ['model'], ['pk'], meta_prefix='parent_')
v.to_sql('fields', engine)
t.to_sql('fields', engine)
But it does not work. Can someone work it and output the SQL table?
My errors looks like this:
TypeError Traceback (most recent call last)
<ipython-input-86-a186308b321b> in <module>()
1
----> 2 v = pd.DataFrame(data['fields'])
3 t = pd.io.json.json_normalize(data['fields'], ['model'], ['pk'], meta_prefix='parent_')
4
5 v.to_sql('fields', engine)
TypeError: list indices must be integers or slices, not str
I want to create two tables. One include 'fields', 'model' and 'pk'.And another table include all the values in 'fields'.
The schema looks like this: enter image description here
TypeError Traceback (most recent call last) <ipython-input-86-a186308b321b> in <module>() 1 ----> 2 v = pd.DataFrame(data['fields']) 3 t = pd.io.json.json_normalize(data['fields'], ['model'], ['pk'], meta_prefix='parent_') 4 5 v.to_sql('fields', engine) TypeError: list indices must be integers or slices, not strdata['fields']string type? If it is,v = pd.DataFrame(data['fields'])will make error