Rows returned by pyodbc are not JSON serializable
When you are iterating over rows
, each row
is a Row
instance and not a list
. You can convert it to a list (which is JSON serializable) as follows:
rows = cursor.fetchall()for row in rows: data.append([x for x in row]) # or simply data.append(list(row))
If you want it to return a dictionary of key/value pairs instead of a list of values then take a look at this answer.