If you don't want to change the configuration for your entire API, you can return an unsorted JSON response using a small function like this:
def make_unsorted_response(results_dict: dict, status_code: int):
resp = make_response({}, status_code)
j_string = json.dumps(results_dict, separators=(',', ':'))
resp.set_data(value=j_string)
return resp
I like using flask-restx, here's how I'd use this function:
@api.route('/test', endpoint='test')
@api.doc(params={}, description="test")
class Health(Resource):
def get(self):
my_dict = {'z': 'z value',
'w': 'w value',
'p': 'p value'}
results_dict = {"results": my_dict}
return make_unsorted_response(results_dict, 200)
When called it returns an unsorted response like this:
{"results":{"z":"z value","w":"w value","p":"p value"}}
The syntax is pretty much the same in Flask. I would also recommend you add some exception handling to the function if you decide to use it, I'm just showing a basic example.