I am fetching data from a MySQL database and writing into a CSV file. This looks like this :
with open("output.csv", "ab+") as csv_file:
csv_writer = csv.writer(csv_file)
csv_writer.writerows(db_cursor)
This works fine with normal columns. However, I have a column which is of type LONGTEXT and has JSON data in it.
csv_writer adds extra quotes around each key value in the JSON when it creates the CSV file.
i.e., if my column has this value :
{"key":"value"}
the output.csv file has :
"{""key"" : ""value""}"
What I want is :
"{\"key\" : \"value\"}"
How do I achieve this ?
(I have to read this file again in a ruby app and recreate the json. With this extra quotes, I am not sure how do I handle that!)