Search code examples
pythonsqlflask

How to customize output in API?


I am making a simple API using Python and Flask Framework and I am getting the correct output, but the problem with output is that It come in alphabetical order and I want to customize it in specific order.

This is the code I wrote

First part of code Second Part of code

Output I am getting

{
    "alma": None,
    "close": 1549.6,
    "date":2015-02-02,
    "high": 1556.7,
    "low": 1544.8,
    "name": "ACC",
    "open": 1554.9,
    "volume": 1441
  }

Output I want

{
    "name": "ACC",
    "date":2015-02-02,
    "open": 1554.9,
    "high": 1556.7,
    "low": 1544.8,
    "close": 1549.6,
    "volume": 1441
    "alma": None
  },

I want to change the Output format but I don't know how to do it, If anyone know pleas tell me.


Solution

  • Flask offers the following configuration:

    app = Flask(__name__)
    app.config['JSON_SORT_KEYS'] = False