Stringify JSON in Logic App Stringify JSON in Logic App json json

Stringify JSON in Logic App


Do you need the stringified message to include opening and closing double quotes?

I've tried this and it worked for me.

  1. I have my JSON object as an output of a compose
  2. Then, I initialised a variable with the Base64 encoded value of the escaped stringified JSON (you need to add ALL the proper escaping required,mine was just a PoC)
  3. Then, you send the variable already in Base64 to Service Bus. (You need to remove the encoding on that action).

    "actions": {    "Compose_JSON_Object": {        "inputs": {            "message": "I want this as a string"        },        "runAfter": {},        "type": "Compose"    },    "Initialise_Variable_with_Stringified_JSON_Base64_Encoded": {        "inputs": {            "variables": [                {                    "name": "jsonAsStringBase64",                    "type": "String",                    "value": "@base64(concat('\"', replace(string(outputs('Compose_JSON_Object')), '\"', '\\\"'), '\"'))"                }            ]        },        "runAfter": {            "Compose_JSON_Object": [                "Succeeded"            ]        },        "type": "InitializeVariable"    },    "Send_message": {        "inputs": {            "body": {                "ContentData": "@variables('jsonAsStringBase64')",                "ContentType": "text/plain"            },            "host": {                "connection": {                    "name": "@parameters('$connections')['servicebus']['connectionId']"                }            },            "method": "post",            "path": "/@{encodeURIComponent(encodeURIComponent('temp'))}/messages",            "queries": {                "systemProperties": "None"            }        },        "runAfter": {            "Initialise_Variable_with_Stringified_JSON_Base64_Encoded": [                "Succeeded"            ]        },        "type": "ApiConnection"    }},

This way, I got the message stringified.

HTH