I receive this json response from web page
data=%7B%22header%22%3A%22%7B%5C%22salno%5C%22%3A%5C%220%5C%22%2C%5C%22saldt%5C%22%3A%5C%22Wed+Jul+28+2021+00%3A33%3A40+GMT%2B0530+(India+Standard+Time)%5C%22%2C%5C%22soldto%5C%22%3A%5C%22%5C%22%2C%5C%22remark%5C%22%3A%5C%22%5C%22%2C%5C%22totqty%5C%22%3A310%2C%5C%22subtot%5C%22%3A20251%7D%22%2C%22details%22%3A%22%5B%7B%5C%22status%5C%22%3A%5C%22old-modified%5C%22%2C%5C%22saldtlid%5C%22%3A%5C%221%5C%22%2C%5C%22itemnm%5C%22%3A%5C%22item1%5C%22%2C%5C%22qty%5C%22%3A%5C%2218%5C%22%2C%5C%22rate%5C%22%3A%5C%2212.00%5C%22%2C%5C%22amount%5C%22%3A%5C%22216.00%5C%22%7D%2C%7B%5C%22status%5C%22%3A%5C%22new-record%5C%22%2C%5C%22saldtlid%5C%22%3A%5C%22-10%5C%22%2C%5C%22itemnm%5C%22%3A%5C%22new+item%5C%22%2C%5C%22qty%5C%22%3A%5C%2210%5C%22%2C%5C%22rate%5C%22%3A%5C%2210.00%5C%22%2C%5C%22amount%5C%22%3A%5C%22100.00%5C%22%7D%5D%22%7D&csrfmiddlewaretoken=q1ortMN1jyzBIJVn6qOREBLiNr3Lc7njhvI24lT93gLb5VNzWutot0qDeNvlyY5d
the actual object contains invoice information and one csrfmiddlewaretoken the invoice data has 1 header dict object and multiple detail dict array how to convert the above to python objects so that I can process it
standard urllib
library can unquote this. See the relevant docs
from urllib import parse
import json
from pprint import pprint
data_in = "%7B%22header%22%3A%22%7B%5C%22salno%5C%22%3A%5C%220%5C%22%2C%5C%22saldt%5C%22%3A%5C%22Wed+Jul+28+2021+00%3A33%3A40+GMT%2B0530+(India+Standard+Time)%5C%22%2C%5C%22soldto%5C%22%3A%5C%22%5C%22%2C%5C%22remark%5C%22%3A%5C%22%5C%22%2C%5C%22totqty%5C%22%3A310%2C%5C%22subtot%5C%22%3A20251%7D%22%2C%22details%22%3A%22%5B%7B%5C%22status%5C%22%3A%5C%22old-modified%5C%22%2C%5C%22saldtlid%5C%22%3A%5C%221%5C%22%2C%5C%22itemnm%5C%22%3A%5C%22item1%5C%22%2C%5C%22qty%5C%22%3A%5C%2218%5C%22%2C%5C%22rate%5C%22%3A%5C%2212.00%5C%22%2C%5C%22amount%5C%22%3A%5C%22216.00%5C%22%7D%2C%7B%5C%22status%5C%22%3A%5C%22new-record%5C%22%2C%5C%22saldtlid%5C%22%3A%5C%22-10%5C%22%2C%5C%22itemnm%5C%22%3A%5C%22new+item%5C%22%2C%5C%22qty%5C%22%3A%5C%2210%5C%22%2C%5C%22rate%5C%22%3A%5C%2210.00%5C%22%2C%5C%22amount%5C%22%3A%5C%22100.00%5C%22%7D%5D%22%7D"
data_out = parse.unquote(data_in)
print(type(data_out))
print(data_out)
print('----------')
data_json = json.loads(data_out)
print(type(data_json))
pprint(data_json, indent=4)
output
<class 'str'>
{"header":"{\"salno\":\"0\",\"saldt\":\"Wed+Jul+28+2021+00:33:40+GMT+0530+(India+Standard+Time)\",\"soldto\":\"\",\"remark\":\"\",\"totqty\":310,\"subtot\":20251}","details":"[{\"status\":\"old-modified\",\"saldtlid\":\"1\",\"itemnm\":\"item1\",\"qty\":\"18\",\"rate\":\"12.00\",\"amount\":\"216.00\"},{\"status\":\"new-record\",\"saldtlid\":\"-10\",\"itemnm\":\"new+item\",\"qty\":\"10\",\"rate\":\"10.00\",\"amount\":\"100.00\"}]"}
----------
<class 'dict'>
{ 'details': '[{"status":"old-modified","saldtlid":"1","itemnm":"item1","qty":"18","rate":"12.00","amount":"216.00"},{"status":"new-record","saldtlid":"-10","itemnm":"new+item","qty":"10","rate":"10.00","amount":"100.00"}]',
'header': '{"salno":"0","saldt":"Wed+Jul+28+2021+00:33:40+GMT+0530+(India+Standard+Time)","soldto":"","remark":"","totqty":310,"subtot":20251}'}