Created
December 14, 2013 09:09
-
-
Save atsuya046/7957165 to your computer and use it in GitHub Desktop.
create sqlite database file from json file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding:utf-8 -*- | |
import json | |
import sqlite3 | |
JSON_FILE = "some.json" | |
DB_FILE = "some.db" | |
traffic = json.load(open(JSON_FILE)) | |
conn = sqlite3.connect(DB_FILE) | |
foo = traffic[0]["foo"] | |
bar = traffic[0]["bar"] | |
data = [foo, bar] | |
c = conn.cursor() | |
c.execute('create table table_name (foo, bar)') | |
c.execute('insert into table_name values (?,?)', data) | |
conn.commit() | |
c.close() |
Is something similar available for Java?
data
should be a tuple and not a list e.g. data = (foo, bar)
in order to be compliant with sqlite3 module.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
getting following error:
Traceback (most recent call last):
File "./jsonToSqlite.py", line 11, in
foo = traffic[0]["foo"]
KeyError: 0