Skip to content

Instantly share code, notes, and snippets.

@goFrendiAsgard
Last active December 17, 2015 16:49
Show Gist options
  • Save goFrendiAsgard/5642123 to your computer and use it in GitHub Desktop.
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
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)
@wintangmurtiari
Copy link

thank you frendi !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment