I have a unicode object which should represent a json but it contains the unicode u in it as part of the string value e.g. u'{u\'name\':u\'my_name\'}'
My goal is to be able to load this into a json object. Just using json.loads fails. I know this happens because of the u inside the string which are not part of an acceptable json format.
I, then, tired sanitizing the string using replace("u\'", "'"), encode('ascii', 'ignore') and other methods without success.
What finally worked was using ast.literal_eval but I'm worried about using it. I found a few sources online claiming its safe. But, I also found other sources claiming it's bad practice and one should avoid it.
Are there other methods I'm missing?
ast.literal_evalis safe.uvalues etc.? Doesast.literal_evalhave any negative downsides to it?"(double quotes) to surround keys and strings. And this is a reason forjson.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1). I have also suggested Unsafe way, just ignore that if you wish. You will need to find a way in case if your data string containsuas part of original data.