I have a json object of the form
{
"483329":
{"Dairy_free": false,
"Gluten_free": true,
"Vegetarian": false,
"Vegan": false,
"ketagonic": false},
"577539":
{"Dairy_free": true,
"Gluten_free": false,
"Vegetarian": true,
"Vegan": true,
"ketagonic": false}
}
Where the schema is
| id | Dairy_free | Gluten_free | Vegetarian | Vegan| ketagonic|
+----+------------+-------------+------------+------+-----------+
Is there a way without re-generating the json to insert the json object to mysql, using mysqlcursors?
sql_insert = INSERT INTO allergies VALUES (Default, %s %s %s %s %s);"
cursor = config.cursor
for obj in json_objects <---- this is where I need to transfer to suitable object
try:
affected_count = cursor.execute(sql_insert, (object))
config.dbconnection.commit()
except Exception as e:
print e