I have a Unicode string my_string = 'SGtjPQ\\u003d\\u003d' and a dictionary (2 backslashes)
data = {'key': my_string}
I need to provide json-response in bytes, so I do the following
response = json.dumps(data)
return response.encode()
and eventually a have this result b'{"key": "SGtjPQ\\\\u003d\\\\u003d"}' (4 backslashes). But I want my_string in the response to be exactly as it was (with 2 backslashes). How to prevent this auto-escaping and get result b'{"key": "SGtjPQ\\u003d\\u003d"}'
response.replace(b'\\\\', b'\\')to explicitly replace that slashes.