Hi Aditya Singh,
Thanks for reaching out to Microsoft Q&A.
The errors you're encountering stem from special characters in the error message that are causing JSON parsing issues when the message is sent to the Logic App. Specifically, characters like newline (\n
), carriage return (\r
), backslash (\
), and double quotes ("
) can break the JSON structure if not properly escaped or encoded.
To resolve this issue, you can use the encodeUriComponent()
function in ADF to encode the error message. This function replaces special characters with their URI-encoded equivalents, ensuring that the JSON payload remains valid when sent to the Logic App.
You can try modifying your expression similar to below:
@concat(
'Target: ',
activity('raw_data_quality_pipeline')?.error?.target,
', Error Message: ',
encodeUriComponent(activity('raw_data_quality_pipeline')?.error?.message)
)
Steps to try:
- Update the ADF Pipeline Expression: Replace your existing expression with the one provided above. The
encodeUriComponent()
function will encode special characters in the error message. - Modify the Logic App to Decode the Error Message: In your Logic App, use the
decodeUriComponent()
function to decode the error message back to its original form before including it in the email notification. Here's how you can do it:- When you receive the error message in the Logic App (probably as part of the HTTP request body), apply the
decodeUriComponent()
function to it. For ex: if you're using the value in an email body, you can set the email content to:
- When you receive the error message in the Logic App (probably as part of the HTTP request body), apply the
@{decodeUriComponent(triggerBody()?['ErrorMessage'])}
Replace 'ErrorMessage'
with the actual key you're using in the HTTP request body.
Explanation:
- Why
encodeUriComponent()
Helps: This function ensures that all special characters are percent encoded, which makes the error message safe to include in JSON payloads without causing parsing errors. Handling in Logic App: By decoding the error message in the Logic App, you retrieve the original error message content, which can then be included in the email body.
If you prefer not to encode and decode the error message, you can remove problematic characters using the replace()
function multiple times. However, this approach is not reliable because you might miss some special characters. The encoding method is more robust and recommended & this method may still result in errors if there are other special characters in the error message.
Please 'Upvote'(Thumbs-up) and 'Accept' as an answer if the reply was helpful. This will benefit other community members who face the same issue.