I have a bytestring like this:
b'{\r\n "hello": "world"\r\n}'
, retrieved from a request in JSON format. I would like to parse it into a Python dictionary so it looks like this: {"hello": "world"}
. I have tried with ast.literal_eval()
but that throws an error. How would you go about doing it?
Asked
Active
Viewed 26 times
0

Josh Merrian
- 291
- 3
- 11
-
You're missing the intermediary step of transforming your bytestring into a normal string by using `bytestring.decode('utf8')`. Also, don't forget to add minimum reproducible code to your questions as well as the stacktrace/full error that you are receiving and how you cause it! – Jason Rebelo Neves Feb 16 '21 at 11:03
-
`json.loads(b'{\r\n "hello": "world"\r\n}')` – Ajay Feb 16 '21 at 11:05