Im having issues with the following code trying to parse a string to dictionary because of escaping characters , I will post an example :
string = """ {"key" : "value 'others' = \"one \" "} """
json.loads(string)
json cannot load because it gets the following string with too many double quotes :
{"key" : "value 'others' = "one " "}
In fact I dont need to load with json , I could simply do an eval :
ast.literal_eval(string)
So far so good, problem is Im not able to delete the escaped double quotes strings with replace (example : s.replace('\"','') ), so , there is some low level string manipulation to achieve what I want to ? I would like to get a valid json syntax :
{"key" : "value 'others' = one "}
Or be able to get python not deleting backslash :
{"key" : "value 'others' = \"one\" "}
As Francois stated this can be achieved with a raw string :
rawstring = r"my string \""
My problem is related to the string placed already into a non raw string variable, so I need some way to get that non raw string to be recasted to raw string in order to parse to a dictionary data structure using json or ast.literal_eval