Inserting JSON into MySQL using Python

前端 未结 9 906
我在风中等你
我在风中等你 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:15

    The most straightforward way to insert a python map into a MySQL JSON field...

    python_map = { "foo": "bar", [ "baz", "biz" ] }
    
    sql = "INSERT INTO your_table (json_column_name) VALUES (%s)"
    cursor.execute( sql, (json.dumps(python_map),) )
    

提交回复
热议问题