python - Issue with sending nested json objects to sqlite db -
i have large file of json objects 1 object per line. send data sqlite database. each json object formatted this:
{"1": {"google": 5}, "2": "", "3": 0.0, "4": [10.0, 20.0, 30.0, 20.0], "6": "", "7": 2, "8": {}, "9": 1.0, "10": 0.0}
i tried code , got following error:
query = "insert daily values (?,?,?,?,?,?,?,?,?,?)" columns = ['1', '2', '3', '4', '5', '6','7', '8', '9', '10'] open(json_file) f: head = islice(f, 5) x in head: line = json.loads(x) keys = tuple(line[c] c in columns) c.execute(query, keys) interfaceerror: error binding parameter 0 - unsupported type.
two questions:
1) why getting error? assume has the first hey's value being nested dict, i'm not sure how fix it.
2) created table this:
c.execute('''create table daily (1 text, 2 text, 3 text, 4 text, 5 text, 6 text, 7 text, 8 text, 9 text, 10 text)''')
ideally, have separate columns key:value pair first key in object. again, assume possible, i'm not quite sure how this.
if have mongoclient
connected running server, insert
json
database:
client.db.collection.insert(json) # insert json in collection of database db
to retrieve entries simply, use find
method of given collection
of database db
:
entries = client.db.collection.find() # find entries without specified argument
Comments
Post a Comment