New line character "\\n" in json output not rendering as new line

Hello:

(edited to account for this editor removing doubled slashes)

I’ve got this mermaid notation output from my AI Agent. Problem is it is using this new line character which looks like this “\n” (single slash) but is actually an escaped version “\n” (double slash) under the hood as far as I can tell. I know this because vscode search and replace function only recognizes “\n” (double slash) when I replace it with actual (shift+enter) line breaks. I’ve tried so many variations of scripts to replace this “\n” (double slash) with something else that will trigger an actual line break when pasting into a mermaid preview. I’ve even tried spreading out the mermaid chunk into an array before running it through scripts…still no luck.

Anyone have any ideas or techniques to get this mermaid blob to render new lines without external processing like vscode find/replace?

Thanks for your time.

What I have:

What I need:
image

Text version for your convenience---------------------------------------
graph TD;\n A[Start] → B[Step 1]\n B → C[Step 2]\n C → D{Condition?}\n D – Yes → E[Step 3]\n D – No → F[Step 4]\n F → D\n E → G[Step 5]\n G → H[Step 6]\n H → I{End Condition?}\n I – Yes → J[Step 7]\n J → H\n I – No → K[End]\n K → L[Document Observations]\n L → M[End]

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hey @chris4 , use the Javascript function replace(/\\n/g, '\n') as shown in the image below

1 Like

Thank you.

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