❗ n8n HTTP Request Node — Cannot Send Dynamic JSON from Previous Node ($json not working)

Hi everyone,
I’m using n8n v1.88.0 (Self-Hosted) and trying to push an AI-generated message to Rocket.Chat using the HTTP Request node. Static content works fine — but when I try to send dynamic content via JSON, I keep getting errors like:

:x: JSON parameter needs to be valid JSON
:x: Bad request - must match exactly one schema in oneOf
:x: The value "$json" is not supported!


:white_check_mark: What Works:

This static JSON body successfully sends to Rocket.Chat:

json

CopyEdit

{
  "channel": "#ai-chat",
  "text": "Test message",
  "alias": "AI Agent",
  "emoji": ":robot_face:"
}

:x: What Fails (Dynamic JSON Approaches Tried)

We’ve tested every known method and can’t get dynamic text (like {{ $json.text }}) to work. Here’s a list of what we tried:

1. $json (expression) directly in JSON field:

json

CopyEdit

$json

:exclamation:Error: “The value $json is not supported!”


2. Full expression block:

js

CopyEdit

={{ 
  {
    "channel": "#ai-chat",
    "text": $json.text,
    "alias": $json.alias,
    "emoji": $json.emoji
  } 
}}

:exclamation:Error: JSON parameter needs to be valid JSON


3. Expression interpolation inside string values:

json

CopyEdit

{
  "channel": "#ai-chat",
  "text": "={{ $json.text }}",
  "alias": "={{ $json.alias }}",
  "emoji": "={{ $json.emoji }}"
}

:exclamation:Fails silently or body is interpreted as a literal string.


4. JSON via Set or Edit Fields node:

Used an Edit Fields node or Set node to structure:

json

CopyEdit

{
  "channel": "#ai-chat",
  "text": "{{ $json.output }}",
  "alias": "AI Agent",
  "emoji": ":robot_face:"
}

Looks correct in the preview, but Rocket.Chat rejects the request, possibly due to string escaping.


5. Using Code node:

Formatted and returned JSON from a Code node:

js

CopyEdit

return {
  json: {
    channel: "#ai-chat",
    text: $json.text,
    alias: "AI Agent",
    emoji: ":robot_face:"
  }
};

:white_check_mark: Works fine when hardcoded
:x: Still fails when passed into HTTP Request node unless fields are explicitly replaced again


6. Tried Function node with direct fetch() call

:x: fetch and $http are not supported in the Function node (sandboxed)


:brain: Other Notes:

  • Rocket.Chat API requires channel OR roomId, but channel is definitely valid.
  • When dynamic fields are passed, Rocket.Chat returns:

must have required property 'roomId' | must match exactly one schema in oneOf

We’ve exhausted all formatting tricks and workarounds inside n8n.


:pray: What We Need Help With:

  • Has anyone successfully pushed dynamic text to Rocket.Chat using n8n’s HTTP Request node?
  • Is there a best practice or correct way to pass $json in a format Rocket.Chat will accept?

Thanks in advance for your insights!

See this answer about wrapping the entire JS object in an expression, and converting the whole thing into JSON at the end. Maybe that will help you get the full payload you need in valid JSON format in the HTTP Request node.

{{
  {
    channel: "#ai-chat",
    text: $json.text,
    alias: $json.alias,
    emoji: $json.emoji
  }.toJsonString()
}}