Variable substitution breaks JSON payload in n8n workflow

I’m having trouble sending data to Go High Level using n8n’s HTTP Request node. The weird thing is that my JSON works perfectly when I hardcode the values:

{
  "userInfo": {
    "ABC123DefGhiJkl456": "sample text value"
  }
}

But as soon as I try to use a dynamic variable, the request fails:

{
  "userInfo": {
    "ABC123DefGhiJkl456": "{{ $json.data.text }}"
  }
}

The content in $json.data.text is a long prompt template that defines an AI assistant named Emma with detailed instructions about her role, communication style, and tasks. It includes sections like Identity, Style Guidelines, Response Rules, and specific interaction examples. The text is quite lengthy and contains formatting instructions and behavioral guidelines.

I tested this same content by manually inserting it into the database and it works fine there. So it’s not a length issue or character limit problem.

I’ve experimented with different variables and most work correctly. However, certain variables cause this JSON formatting error and I can’t figure out what makes some work while others don’t. Has anyone experienced similar issues with variable interpolation in n8n JSON payloads?

your prompt text probably has newlines or quotes breaking the JSON structure. switch the variable to expression mode and wrap it like {{ JSON.stringify($json.data.text) }} - this’ll escape all the problematic characters without breaking your payload format.

I’ve encountered this issue as well. The problem often lies with unescaped characters in the dynamic variable content, especially since you’re including lengthy AI instructions that may have quotes or backslashes that disrupt the JSON structure. To resolve it, try using the Expression tab in the HTTP Request node instead of typing directly into the JSON field. By using JSON.stringify() to wrap your variable, you can ensure proper character escaping. Alternatively, if Go High Level allows it, using Body Parameters instead of raw JSON may help, as it avoids JSON parsing issues altogether.

Hit this same issue with complex text in n8n. It’s not always quotes or newlines - invisible characters and encoding problems love to sneak in with long prompt templates. I switched to using a Code node instead of wrestling with the HTTP Request node’s JSON handling. Build your payload in JavaScript, stringify it properly, then send it to a basic HTTP Request. Something like const payload = { userInfo: { "ABC123DefGhiJkl456": items[0].json.data.text } }; return { json: { body: JSON.stringify(payload) } }; You get full control over JSON construction and skip all the variable interpolation headaches.

Check if your prompt template has unescaped backslashes or hidden control characters that don’t show up in the editor. I hit this same issue when sending AI prompts through n8n to external APIs. Wasn’t quotes or newlines - turned out to be invisible Unicode characters that snuck in when I copied content from somewhere else. First thing I’d do is log the actual variable content with a debug node to see what’s really getting passed. What fixed it for me was using a Set node to clean the text variable before the HTTP request. Just strip out non-printable characters with a basic regex replace. That preprocessing killed the JSON corruption without having to rebuild the whole workflow.

Had this exact problem - that’s why I ditched n8n for complex data stuff. When you’re dealing with long content that has special characters, quotes, or formatting like your AI prompt template, n8n’s variable system just breaks the JSON structure.

It’s not even about escaping. n8n processes variables in a way that corrupts your entire payload when you’ve got complex text.

I completely fixed this by switching to Latenode. It handles dynamic content way better, especially for API stuff with Go High Level. The variables actually work reliably and don’t break on long prompts or weird characters.

With Latenode, you can throw that same AI content at it without the JSON breaking. Way better at handling complex data than n8n’s expression system.

You’ll save tons of time debugging this variable mess: https://latenode.com