0

Im trying to load JSON data from an API using the Python json.loads command but Im getting an error message "No JSON Object Could be Decoded".

This is the JSON API data that Im trying to load: https://financialmodelingprep.com/api/financials/income-statement/AAPL

The API call is successful and when I do a "print (response.content)" it prints correctly. However, when I place the response.content into a variable using the json.loads it gives the error message.

In the code below the first Print works well. The second Print gives the error message.

here is my code:

import json
import requests


response = requests.get("https://financialmodelingprep.com/api/financials/income-statement/AAPL")

print (response.content)

data = json.loads(response.content)

print (data)

1 Answer 1

2
import json
import requests

response = 
requests.get("https://financialmodelingprep.com/api/financials/income- 
statement/AAPL")
data = json.loads(response.text.replace("<pre>","").replace("</pre>",""))

print (data)

If you want something more elegant you could use https://html.python-requests.org/

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

2 Comments

Thank you so much. I don't quite understand what you have done but it worked ;-)
The result from the request was actually HTML, not json. So I stripped the HTML and then fed it into the JSON loads method

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.