How to return JsonResponse without using Return in Django

Am building a USSD app that requires me to send a return JsonResponse but i want to do it without using Return. Beacuase i want to a couple of things after the return

payload ={
        "USERID": code_id,
        "MSISDN": serviceCode,
        "MSGTYPE": type_msg,
        "USERDATA": text,
        "SESSIONID": session_id,
        "MSG": response,
           }
return JsonResponse(payload)
     

You can use json module like this...

import json

payload ={
"USERID": code_id,
"MSISDN": serviceCode,
"MSGTYPE": type_msg,
"USERDATA": text,
"SESSIONID": session_id,
"MSG": response,

}

resp = json.dumps(payload)
..... here code .....

return resp
Back to Top