- Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSQLtoJSON_Python.py
More file actions
Latest commit
25 lines (18 loc) · 526 Bytes
/
Copy pathSQLtoJSON_Python.py
File metadata and controls
25 lines (18 loc) · 526 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
importos
importjson
importsqlite3
# CONNECT TO DATABASE
cd=os.path.dirname(os.path.abspath(__file__))
db=sqlite3.connect(database=os.path.join(cd, 'CLData.db'))
# QUERY DATABASE
db.row_factory=sqlite3.Row
cur=db.cursor()
cur.execute("SELECT * FROM cldata")
data= [dict(row) forrowincur.fetchall()]
cur.close()
db.close()
# JSON EXPORT
jsondata=json.dumps(data, indent=4)
withopen(os.path.join(cd, 'CLData_Py.json'),'w') asf:
f.write(jsondata)
print("Successfully migrated SQL data to JSON!")