How to display the entire content of a JSON in Azure Storage Queues using an Azure Function

Fabrício Fortaleza 150 Reputation points
2023-11-27T21:11:17.88+00:00

Hello. I've created an Azure Function that essentially receives a request via an HTTP Trigger containing information in JSON, and this information is sent encrypted. My Function's role is to decrypt this information and save it in a queue created in Azure Storage Explorer. The Function is working fine; however, it's not saving all the information. Example: JSON Information { "status": "approved" }

However, when writing the above information to the storage queue, it only writes "Status" and not the entire information.

Function code below:

@app.route(route="cadastro/analise", auth_level=func.AuthLevel.ANONYMOUS)
@app.queue_output(arg_name="msg", queue_name="analise-cadastro", connection="AzureWebJobsStorage")
def analisar_cadastro(req: func.HttpRequest, msg: func.Out [func.QueueMessage]) -> func.HttpResponse:
    try:
        signature = req.headers.get("SIGNATURE")
        payload = req.get_json()
        x_real_ip = req.headers.get("X-Real-IP")
        
        decoded_token = jwt.decode(signature, key=signature_key, algorithms=["HS256"])
        msg.set(payload)
        logging.info(f"Webhook received: {payload}")
        
        return HttpResponse("Webhook received with success!")

Result in Azure Explorer: Using the first example of JSON sent, the return in Azure explorer displays:
Message Text: Status --> (instead of Status: Approved)

Does anyone know how to fetch the complete JSON information to Azure Explorer? Would it be recommended, before writing to Azure Explorer, to convert the JSON to a TXT, for example, and then write that generated string?"

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,566 questions
Azure Storage Explorer
Azure Storage Explorer
An Azure tool that is used to manage cloud storage resources on Windows, macOS, and Linux.
240 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Fabrício Fortaleza 150 Reputation points
    2023-11-28T18:01:49.15+00:00

    I managed to solve this issue. Right after executing the token decoding, I set a new variable that turns the content of the JSON object sent in the payload into a JSON-formatted string using json.dumps(). The modified code snippet looks like this:

    decoded_token = jwt.decode(signature, key=signature_key, algorithms=["HS256"])
    
            payload_string = json.dumps(payload)
    
            msg.set(payload_string)
    
    1 person found this answer helpful.