How to get the "\n"-problem of a json-code fixed?

Hi,

I am using a “Code in JavaScript” node to convert a JSON file received via a webhook, which is then used by a subsequent HTTP request node. The problem is that sometimes I receive a line from the webhook like "reason": "550-5.1.1 user unknown\n 550 5.1.1 Unknown recipient.", and this causes an issue in the following node. I’ve tried to fix it using the “Code in JavaScript” node with this code:

reason: $json.body.reason ? $json.body.reason.replace(/\n/g, " ") // Replaces actual line breaks with spaces
      .replace(/\\n/g, " ") // Replaces escape sequences \\n with spaces
      : "",

However, the output remains unchanged. How can I fix this?

hello @mel.b

If you receive it inside the JSON, no need to replace the ‘\n’.

Can you share a screenshot of how it looks in the output?

Screenshot 2025-12-11 082627 The problem occurs when the following HTTP request node is supposed to send everything to Microsoft Teams.

Send the message as {{ JSON.stringify( $json.reason ) }}

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.