I'm trying to convert this string into python dict:
q = '{"request_body": "{\\x22username\\x22:\\x222\\x22,\\x22password\\x22:\\x226\\x22,\\x22id\\x22:\\x22e2cad174-736e-3041-cf7e\\x22, \\x22FName\\x22:\\x22HS\\x22}", "request_method": "POST"}'
when I do json.loads(a)
it giving me an error simplejson.decoder.JSONDecodeError: Invalid \escape: line 1 column 19 (char 19)
. So than I decided to convert \x22
into "
. I followed suggestion from this question.
>>> q.decode('string_escape')
'{"request_body": "{"username":"2","password":"6","id":"e2cad174-736e-3041-cf7e", "FName":"HS"}", "request_method": "POST"}'
>>>
But after that "{"
part is invalid.
So my question is what are the possible ways to convert string q
into a python dict?