Ich bin ziemlich neu zu Python/JSON/& Codierung .. versuchen zu lernen, wie Sie das folgende Format von JSON zu SQL-Tabelle erhalten. Ich benutzte Python Pandas und es konvertiert die Json-Knoten in das Wörterbuch. Kann mir bitte jemand bitte helfen zu verstehen wie man das macht.Konvertieren von JSON in SQL-Tabelle
Same json:
{
"Volumes": [
{
"AvailabilityZone": "us-east-1a",
"Attachments": [
{
"AttachTime": "2013-12-18T22:35:00.000Z",
"InstanceId": "i-1234567890abcdef0",
"VolumeId": "vol-049df61146c4d7901",
"State": "attached",
"DeleteOnTermination": true,
"Device": "/dev/sda1"
}
],
"Tags": [
{
"Value": "DBJanitor-Private",
"Key": "Name"
},
{
"Value": "DBJanitor",
"Key": "Owner"
},
{
"Value": "Database",
"Key": "Product"
},
{
"Value": "DB Janitor",
"Key": "Portfolio"
},
{
"Value": "DB Service",
"Key": "Service"
}
],
"VolumeType": "standard",
"VolumeId": "vol-049df61146c4d7901",
"State": "in-use",
"SnapshotId": "snap-1234567890abcdef0",
"CreateTime": "2013-12-18T22:35:00.084Z",
"Size": 8
},
{
"AvailabilityZone": "us-east-1a",
"Attachments": [],
"VolumeType": "io1",
"VolumeId": "vol-1234567890abcdef0",
"State": "available",
"Iops": 1000,
"SnapshotId": null,
"CreateTime": "2014-02-27T00:02:41.791Z",
"Size": 100
}
]
}
bis jetzt .. es das, was ich versuchte, ... in Python:
asg_list_json_Tags=asg_list_json["AutoScalingGroups"]
Tags=pandas.DataFrame(asg_list_json_Tags)
n = []
for i in Tags.columns:
n.append(i)
print n
engine = create_engine("mysql+mysqldb://user:"+'pwd'+"@mysqlserver/dbname")
Tags.to_sql(name='TableName', con=engine, if_exists='append', index=True)
Jede Hilfe tief appreacated ist .. Vielen Dank!
Was scheint das Problem zu sein? Warum funktioniert dieser Code nicht? –
so bekomme ich eine Fehlermeldung, die besagt, dass dict nicht in die Zeichenfolge – DataJanitor
@DataJanitor eingefügt werden kann, möchten Sie __flatten__ Daten speichern? – MaxU