Python: Remove Double Quotes From Json Dumps
I have a database which returns the rows as lists in following format: data = ['(1000,'test value',0,0.00,0,0)', '(1001,'Another test value',0,0.00,0,0)'] After that, I use json_
Solution 1:
You are dumping list of strings so json.dumps does exactly what you are asking for. Rather ugly solution for your problem could be something like below.
def split_and_convert(s):
bits = s[1:-1].split(',')
return (
int(bits[0]), bits[1], float(bits[2]),
float(bits[3]), float(bits[4]), float(bits[5])
)
data_to_dump = [split_and_convert(s) for s in data]
json.dumps(data_to_dump)
Post a Comment for "Python: Remove Double Quotes From Json Dumps"