Thursday, 5 September 2013

#EANF#

#EANF#

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_str = json.dumps(data) to get a JSON string. After
applying json.dumps(), I get the following output:
json_str = ["(1000,\"test value\",0,0.00,0,0)", "(1001,\"Another test
value\",0,0.00,0,0)"]
However, I need the JSON string in the following format:
json_str = [(1000,\"test value\",0,0.00,0,0), (1001,\"Another test
value\",0,0.00,0,0)]
So basically, I want to remove the surrounding double quotes. I tried to
accomplish this with json_str = json_str.strip('"') but this doesn't work.
Then, I tried json_str = json_str.replace('"', '') but this also removes
the escaped quotes.
Does anybody know a way to accomplish this or is there a function in
Python similiar to json.dumps() which produces the same result, but
without the surrounding double quotes?
Any help is appreciated!

No comments:

Post a Comment