Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flask – endpoint returning dictionary instead of list

whenever I create an endpoint to return a list, it returns a number-keyed dictionary instead.

from flask import Flask

app = Flask(__name__)
    
@app.route('/somelist')
def somelist():
    return ['a', 'b', 'c']  

When I go to view the endpoint, I get a dictionary like this:

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What’s going on here? I just want a list!

>Solution :

It is not a dictionary. The 0:, for example is not part of the response that you’ve returned.

The browser JSON extension you are using is showing the list along with its indicies.

Instead, use curl or Postman and inspect the raw response without browser response parsing. Or click on the Raw Data tab…

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading