Search code examples
jsonfirefox-developer-tools

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

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...