Created
August 23, 2022 23:05
-
-
Save skatesham/879814fb56d8ace5864f453e0cb37d5a to your computer and use it in GitHub Desktop.
Get list json and send to table jsqlite
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
import json | |
import sqlite3 | |
connection = sqlite3.connect('db.sqlite') | |
cursor = connection.cursor() | |
cursor.execute('Create Table if not exists Student (name Text, course Text, roll Integer)') | |
traffic = json.load(open('json_file.json')) | |
columns = ['name','course','roll'] | |
for row in traffic: | |
keys= tuple(row[c] for c in columns) | |
cursor.execute('insert into Student values(?,?,?)',keys) | |
print(f'{row["name"]} data inserted Succefully') | |
connection.commit() | |
connection.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment