Converting String into Dictionary via Python containing invalid JSON
Another way, with .replace('\\"', '"')
Code:
import json
input_string = "{\"SOAPAction\":\"http://www.my-website..uk/path/To/service/v1/serviceAndLedger\",\"ID\":\"1sceas2-61ae-379dd-a9cd-c813fb07u8inb\", \"info\": {\"GMT\":\"16/Nov/2022:12:13:46 +0000\", \"client\":\"10.177.147.71:42987\", \"frontend\":\"path/to_my_ip/12.189.66.213:8804\", \"request\":\"POST /path/service HTTP/1.1\", \"body\":\"\\/path\\/of\\/downloaded\\/file.xml\", \"response\":\"-\"}}"
new_string = input_string.replace('\\"', '"')
result_dict = json.loads(new_string)
print(json.dumps(result_dict, indent=4))
Output:
{
"SOAPAction": "http://www.my-website..uk/path/To/service/v1/serviceAndLedger",
"ID": "1sceas2-61ae-379dd-a9cd-c813fb07u8inb",
"info": {
"GMT": "16/Nov/2022:12:13:46 +0000",
"client": "10.177.147.71:42987",
"frontend": "path/to_my_ip/12.189.66.213:8804",
"request": "POST /path/service HTTP/1.1",
"body": "/path/of/downloaded/file.xml",
"response": "-"
}
}
Read more here: Source link
