0

enter image description here

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

3
  • What does the raw JSONP response text look like? Commented Jun 10, 2022 at 9:08
  • I tried to remove padding from the string and used json.loads() Commented Jun 11, 2022 at 8:28
  • 1
    sometime it need only to remove callback=jsonp from url to get normal json - but you didn't show url so we can't check it Commented Jun 11, 2022 at 10:27

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.