Persistent "Invalid JSON" Error in HTTP Request Node Despite Correct Configuration (Docker)

Hello, I am experiencing a persistent “JSON parameter needs to be valid JSON” error in an HTTP Request node that I cannot solve. I am hoping someone can help diagnose the issue. **My Setup:** * n8n Version: 1.107.4 * Deployment: Docker on Windows * Goal: Call the Replicate.com API with a dynamic prompt from a Gemini node. **My Workflow Structure:** 1. A **Google Gemini** node generates a text prompt. I have confirmed it is outputting a clean string. 2. An **Edit Fields (Set)** node then builds the JSON payload as a JavaScript object using this code: ```javascript const promptText = $(‘YOUR_GEMINI_NODE_NAME’).item.json.content.parts[0].text; const payloadObject = { “version”: “a043c6130b561c4ec2788349a42b7d4c803248383f73967d4bab2e9b8932d84d”, “input”: { “prompt”: promptText } }; return payloadObject; ``` 3. The **HTTP Request** node is configured to send this object. **The Problem:** No matter how the HTTP Request node is configured, it fails. * If I set **Body Content Type** to **`JSON`** and the **JSON Body** to `{{ $json.payload }}` (where payload is the object from the Set node), I get the `NodeOperationError: JSON parameter needs to be valid JSON` error inside n8n. * If I use `JSON.stringify()` in the Set node and set the **Body Content Type** to **`Raw`**, n8n sends the request successfully, but the Replicate API returns a `422 Unprocessable Entity` error because it received a string instead of an object. This feels like a catch-22. I am following the standard n8n patterns, but the node is not processing the JSON object correctly. Can anyone see what might be wrong, or is this a potential bug in this version? Thank you.

Please share the JSON for the HTTP node - there might be multiple things wrong in your setup.

PS: your post is quite unreadable, please pay some attention to formatting.

Try changing the JSON body to

{{ $json.payload.toJsonString() }}

and see if that helps.

1 Like

Hello,

Thank you for the quick reply and my apologies for the poor formatting in my original post.

As requested, here is the complete JSON for the failing HTTP Request node (named Start Replicate Prediction).

HTTP Request Node JSON:

JSON

{
  "parameters": {
    "url": "https://api.replicate.com/v1/predictions",
    "authentication": "headerAuth",
    "sendHeaders": true,
    "headerParameters": {
      "parameters": [
        {
          "name": "Content-Type",
          "value": "application/json"
        }
      ]
    },
    "sendBody": true,
    "bodyContentType": "raw",
    "specifyBody": "json",
    "jsonBody": "={{ $json.replicate_payload }}"
  },
  "id": "c1388145-132d-452f-8706-c852ac30a5c4",
  "name": "Start Replicate Prediction",
  "type": "n8n-nodes-base.httpRequest",
  "typeVersion": 4.2,
  "position": [
    2280,
    -160
  ],
  "credentials": {
    "httpHeaderAuth": {
      "id": "Z7jOqFpA3tqNAn8U",
      "name": "My Replicate Key"
    }
  }
}

For full context, here is also the JSON for the “Edit Fields (Set)” node that provides the replicate_payload to the node above:

Edit Fields (Set) Node JSON:

JSON

{
  "parameters": {
    "fields": {
      "values": [
        {
          "key": "replicate_payload",
          "value": "=const promptText = $('Text for Kling AI video Generation').item.json.content.parts[0].text;\n\nconst payloadObject = {\n  \"version\": \"a043c6130b561c4ec2788349a42b7d4c803248383f73967d4bab2e9b8932d84d\",\n  \"input\": {\n    \"prompt\": promptText\n  }\n};\n\nreturn JSON.stringify(payloadObject);"
        }
      ]
    }
  },
  "id": "e2101e4a-939a-4c28-971c-7798b3c959d2",
  "name": "Edit Fields (Set)",
  "type": "n8n-nodes-base.set",
  "typeVersion": 3.4,
  "position": [
    2060,
    -160
  ]
}

Thank you for your help in diagnosing this persistent issue.

Would you like to share your workflow too, @rajpalbishnoi_18?

1 Like

Thank you for your help.

Here is a link to my workflow’s JSON file.

From what I see the Edit Fields node contains the following:

Key:
replicate_payload

Value

const promptText = $('Text for Kling AI video Generation').item.json.content.parts[0].text;  const payloadObject = {   "version": "a043c6130b561c4ec2788349a42b7d4c803248383f73967d4bab2e9b8932d84d",   "input": {     "prompt": promptText   } };  return payloadObject;

The value is not a dynamic field, it is a string containing exactly the text above.

In the HTTP Request node you configured a JSON body with the following content:
{{ $json.replicate_payload }}, which means it will take exactly the text from the Edit Fields value and use it here. The value is not just an invalid JSON, it is not a json to begin with.

This is why it fails.

I can’t see anything odd in this node. Please note that you removed some of the JSON, making it harder for anyone else to test it :slight_smile: Next time if you want to share a node, just select it on the canvas, copy it and paste the code in here. Same for the full workflow.

@jabbson - Thank you for the suggestion. I tried changing the JSON Body to use {{ $json.replicate_payload.toJsonString() }}. Unfortunately, this resulted in a 422 Unprocessable Entity error from the Replicate API with the message Expected: object, given: string. It seems the API rejects a pre-stringified body.

@bartv - As you requested, here is the complete JSON for the failing HTTP Request node and the Edit Fields (Set) node that provides its data.

Edit Fields (Set) Node JSON:

JSON

{
  "parameters": {
    "fields": {
      "values": [
        {
          "key": "replicate_payload",
          "value": "=const promptText = $('Text for Kling AI video Generation').item.json.content.parts[0].text;\n\nconst payloadObject = {\n  \"version\": \"a043c6130b561c4ec2788349a42b7d4c803248383f73967d4bab2e9b8932d84d\",\n  \"input\": {\n    \"prompt\": promptText\n  }\n};\n\nreturn payloadObject;"
        }
      ]
    }
  },
  "id": "e2101e4a-939a-4c28-971c-7798b3c959d2",
  "name": "Edit Fields (Set)",
  "type": "n8n-nodes-base.set",
  "typeVersion": 3.4,
  "position": [
    2060,
    -160
  ]
}

HTTP Request Node JSON:

JSON

{
  "parameters": {
    "bodyContentType": "json",
    "jsonBody": "={{ $json.replicate_payload }}",
    "authentication": "headerAuth",
    "sendHeaders": true,
    "headerParameters": {
      "parameters": []
    },
    "sendBody": true,
    "specifyBody": "json"
  },
  "id": "c1388145-132d-452f-8706-c852ac30a5c4",
  "name": "Start Replicate Prediction",
  "type": "n8n-nodes-base.httpRequest",
  "typeVersion": 4.2,
  "position": [
    2280,
    -160
  ],
  "credentials": {
    "httpHeaderAuth": {
      "id": "Z7jOqFpA3tqNAn8U",
      "name": "My Replicate Key"
    }
  }
}

This still results in the NodeOperationError: JSON parameter needs to be valid JSON error inside n8n.

It feels like a catch-22. When I send the data as an object, n8n fails. When I send it as a string, the Replicate API fails.

Thank you for your help in diagnosing this.

This is not what I see in your workflow. This is your Edit Fields node:

this is also not what I see in the workflow. This is what I see

You have to sync up what you are sharing and what’s in the full workflow JSON you provided earlier.

this is not true, it outputs a string with JS code

I can almost guarantee this issue is not a bug with n8n version 1.107.4.

After running the Edit Fields node and then inspecting the http request node I see this is what the http request’s JSON body looks like

This is still not a JSON, and because this isn’t, you get an error you get.

Thank you for your help. My apologies for the issues with sharing my workflow; the forum is blocking all external links from my new account. As requested, I am now pasting the full JSON of my latest workflow file below, inside a collapsible section.

The core problem is that n8n seems to be executing an old, cached version of my workflow, even after a full hard restart (docker rmi and docker run).

Proof of the Caching Issue: Even though my Edit Fields (Set) node is correctly configured in Expression mode in my editor, the output from the failed execution shows it ran in Fixed mode (it outputted the raw code instead of the result):

JSON

[
  {
    "replicate_payload": "const promptText = $('Text for Kling AI video Generation').item.json.content.parts[0].text;\\n\\nconst payloadObject = {\\n  \"version\": \"a043c6130b561c4ec2788349a42b7d4c803248383f73967d4bab2e9b8932d84d\",\\n  \"input\": {\\n    \"prompt\": promptText\\n  }\\n};\\n\\nreturn payloadObject;"
  }
]

The Final Error: This incorrect output then causes the Start Replicate Prediction node to fail with this error:

JSON

{
  "errorMessage": "JSON parameter needs to be valid JSON",
  "errorDetails": {},
  "n8nDetails": {
    "nodeName": "Start Replicate Prediction",
    "nodeType": "n8n-nodes-base.httpRequest",
    "nodeVersion": 4.2,
    "itemIndex": 0,
    "time": "8/27/2025, 12:05:03 AM",
    "n8nVersion": "1.107.4 (Self Hosted)",
    "binaryDataMode": "default"
  }
}

Click to expand my full workflow JSON

JSON

This seems to be a caching or state management bug. Any help would be greatly appreciated. Thank you.

And this is still not a bug. You are still putting code in a set node and hoping it will automagically execute. Set node is not for running code. Code node is for running code. There is a way to do it, but just use the code node, please.

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