Good day. Can not link python, json and mssql.

There is a test json. I am trying to load it into the database in one cell. After that, unload it back and work with it. All this is needed to understand how it works. But there were problems .. Download, like? it turns out fine, but to unload and work with it is not. To load the base cell I use this:

parsed_string = json.loads(json_string) cursor.execute("update Table set Status = ? where Name like ? ",(json.dumps(parsed_string), "Blabla")) cnxn.commit() 

To unload from the cell

 cursor.execute("""select Status from Table where Name like ?""", "Blabla") cursor.fetchall() 

Here are the requests for loading and unloading ... How to continue to work with what happened? Python output, after unloading from the cell. I do not understand what is wrong with the format, because everything is stored in base normally.

 "{\"orderID\": 42, \"orderContents\": [{\"productName\": \"keyboard\", \"quantity\": 1, \"productID\": 23}, {\"productName\": \"mouse\", \"quantity\": 1, \"productID\": 13}], \ 

    1 answer 1

    Loading:

     s = json.dumps(DATA) cursor.execute("update Table set Status = ? where Name like ? ",(s, "Blabla")) cnxn.commit() 

    Pumping:

     cursor.execute("""select Status from Table where Name like ?""", "Blabla") res = cursor.fetchall() DATA = json.loads(res[0][X]) 
    • you made my day. and also corrected my syntax. Can you explain what values ​​and what it gets res [0] [X]? - gasasder
    • res is the result of the query, res [0] is the first line of the query, res [0] [0] is the first column for the first line of the result - Andrio Skur
    • intuitively understood it, but now everything is exactly clear! thanks - gasasder