I'm using MySQL connector in Python to store and get some JSON data. I'm having problem with getting the stored JSON value as actual Python data type. Hope someone could point me to the right direction.
Let's say I have the following table, TestTable;
id data
1 {"val": 100.5}
2 {"val": true}
And I have the following SQL query:
SELECT id, data->"$.val" FROM TestTable;
- When I run the query int the mysql client's terminal, the result looks good
- When I run the query in a Python script, the results for "val" are of type string for the float value (ie. '100.5') and boolean for the bool value (ie. true)
This is the Python code
cmd = "SELECT id, data->"$.val" FROM TestTable;"
mysql_cur.execute(cmd)
res = mysql_cur.fetchall()
mysql_cur.close()
# res has id and val. id is of type int, val is of type string for float value and type bool for boolean value
How do I get the result into Python's data type, ie. float and bool?
Thanks,