Inserting JSON into MySQL using Python

前端 未结 9 903
我在风中等你
我在风中等你 2020-12-08 03:50

I have a JSON object in Python. I am Using Python DB-API and SimpleJson. I am trying to insert the json into a MySQL table.

At moment am getting errors and I believ

9条回答
  •  青春惊慌失措
    2020-12-08 04:01

    Here's a quick tip, if you want to write some inline code, say for a small json value, without import json. You can escape quotes in SQL by a double quoting, i.e. use '' or "", to enter ' or ".

    Sample Python code (not tested):

    q = 'INSERT INTO `table`(`db_col`) VALUES ("{k:""some data"";}")'
    db_connector.execute(q)
    

提交回复
热议问题