This repository has been archived on 2023-06-09. You can view files and clone it, but cannot push or open issues or pull requests.
jarvis-server/utils/flask_utils.py
Mathieu B 8131b046b2 Base
2021-07-26 18:23:32 +02:00

17 lines
392 B
Python

import json
def get_data_in_request(request):
data_str = str(request.data.decode('utf8')).replace('"', '\"').replace("\'", "'")
# if no data return an empty json to avoid error with json.loads below
if not data_str:
return {}
data_json = json.loads(data_str)
if not isinstance(data_json, dict):
data_json = json.loads(data_json)
return data_json