Last active
December 17, 2015 16:49
-
-
Save goFrendiAsgard/5642123 to your computer and use it in GitHub Desktop.
Decoding json into SQL in python.
Asked by https://www.facebook.com/wintang.murtiari
This file contains hidden or 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 | |
# this is your json | |
my_json_data = '{"nick_name" : "Annakin", "family_name" : "Skywalker"}' | |
# this is the decoded json | |
my_data = json.loads(my_json_data) | |
# sql command | |
sql = "INSERT INTO tbl(nick_name, family_name) VALUES('"+my_data["nick_name"]+"', '"+my_data["family_name"]+"')" | |
# make connection and cursor | |
import sqlite3 | |
conn = sqlite3.connect("db/pokemon.db") # or use :memory: to put it in RAM | |
cursor = conn.cursor() | |
# run the sql command | |
cursor.execute(sql) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you frendi !