pythonjsonjsonp

How to parse JSONP response in python?


enter image description here

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


Solution

  • 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