Prevent Flask jsonify from sorting the data Prevent Flask jsonify from sorting the data flask flask

Prevent Flask jsonify from sorting the data


Yes, you can modify this using the config attribute:

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

However, note that this is warned against explicitly in the documentation:

By default Flask will serialize JSON objects in a way that the keys are ordered. This is done in order to ensure that independent of the hash seed of the dictionary the return value will be consistent to not trash external HTTP caches. You can override the default behavior by changing this variable. This is not recommended but might give you a performance improvement on the cost of cacheability.