How to Use API Data in Flask Application (Display API Content in Jinja Template)

If you want to display content from 3rd part API services or from headless CMS like Strapi, this tutorial definitely going to help you.

flask access 3rd party api contentPin

json.loads – It takes a string as input and returns a dictionary as output.

json.dumps – It takes a dictionary as input and returns a string as output. It turns python data like dict, list and returns this JSON as a string.

.json() – If the API URL returned JSON as a result, then use this


import requests
response = requests.get('')
output_dict = response.json()


json — JSON encoder and decoder (From Official Python Documentation)

SEE ALSO: Web API for Beginners

Common Error When Accessing JSON data in Flask(Python) App

Error 1: JSON object must be str, bytes or bytearray, not dict

When you try to call json.loads with dict as input, this kind of error will appear.


First, add the input in json.dumps and store the value in a new variable,

Now load the new variable as json.loads input


json_content = {"('Hello',)": 6, "('Hi',)": 5}
v1 = json.dumps(json_content)
v2= json.loads(v1)


Error 2: dump() missing 1 required positional argument: ‘fp'


Use json.dumps() instead. json.dump()


About The Author

Scroll to Top
Share to...