How to parse JSONP response in python?

317 Views Asked by At

enter image description here

How can i parse JSONP response, i tried json.loads(), but it will never work for JSONP

1

There are 1 best solutions below

0
MUHAMMAD SHAHID RAFI C P On BEST ANSWER

By the reading following

JSONP is JSON with padding, that is, you put a string at the beginning and a pair of parenthesis around it.

I tried to remove padding from the string and used json.loads()

from json import loads
response = requests.get(link)
startidx = response.text.find('(')
endidx = response.text.rfind(')')
data = loads(response.text[startidx + 1:endidx])

it's working