I am still on python 2.7. I have a list of list in which I have some strings with double quotes. Below is what I have
new_row = [['<a href=/account_dtls/risks/edit/ACC-RISK-136053>ACC-RISK-136053</a>', 'Customer_152', 'External', 'Geographic / Diplomatic', u'Account', u'<span title=something "was" okay>something "was" okay</span>', 'gowri.subramanian', 'Open', 'saved', 'Client Location']]
I wish to convert it into a json. I follow the below steps in python interpreter in terminal
<type 'list'>
>>> json.dumps(new_row)
'[["<a href=/account_dtls/risks/edit/ACC-RISK-136053>ACC-RISK-136053</a>", "Customer_152", "External", "Geographic / Diplomatic", "Account", "<span title=something \\"was\\" okay>something \\"was\\" okay</span>", "gowri.subramanian", "Open", "saved", "Client Location"]]'
>>>
that gave me a neat json string with double quotes escaped. But my problem is I am running DJANGO and within it, I convert the same list of list into json and I get the below printed in my log file.
[["<a href=/account_dtls/risks/edit/ACC-RISK-136053>ACC-RISK-136053</a>", "Customer_152", "External", "Geographic / Diplomatic", "Account", "<span title=something \"was\" okay>something \"was\" okay</span>", "gowri.subramanian", "Open", "saved", "Client Location"]]
Notice that the double quotes around the word 'was' were not escaped with double backslashes and instead with single backslash. I pass this to front-end and I try to read it using JSON.parse() but it throws below error
Uncaught SyntaxError: Unexpected token '&'
When I checked it was like this
[["<a href=/account_dtls/risks/edit/ACC-RISK-136053>ACC-RISK-136053</a>", "Customer_152", "External", "Geographic / Diplomatic", "Account", "<span title=something \"was\" okay>something \"was\" okay</span>", "gowri.subramanian", "Open", "saved", "Client Location"]]
So I tried replacing the "
with "
replace(/"/g,'"')
But now I get the below error.
VM86:1 Uncaught SyntaxError: Unexpected token w in JSON at position 164
I am totally frustrated here. Can someone please help me what is going on here? and how shall I fix this?