Python Forum

Full Version: How to insert JSON into MSSQL
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello guys,

I implemented a flask REST api. I want to insert JSON data into MSSQL 2016. I wonder if I can use OPENJSON in my python.I installed pyodbc and connect to MSSQL. How can I use insert statment like below in my python code?

INSERT INTO SalesReport  
SELECT SalesOrderJsonData.*  
FROM OPENJSON (@jsonVariable, N'$.Orders.OrdersArray')  
           WITH (  
              Number   varchar(200) N'$.Order.Number',   
              Date     datetime     N'$.Order.Date',  
              Customer varchar(200) N'$.AccountNumber',   
              Quantity int          N'$.Item.Quantity'  
           )  
  AS SalesOrderJsonData;  
Best Regards.
Any help please?
I don't normally do this buuut... https://goo.gl/hZKBCm