"JSON parameters needs to be a valid JSON"

I am trying to parse a resume of mine that is uploaded to my Google Drive and send it to a Gemini endpoint with an HTTP request. I want the model to parse through my resume and give me a template mail that I can use to connect with different people I want to connect with in academia.

It gives out an error: JSON parameter needs to be a valid JSON

Here is my workflow:

Output:

{
  "errorMessage": "JSON parameter needs to be valid JSON",
  "errorDetails": {},
  "n8nDetails": {
    "nodeName": "HTTP Request1",
    "nodeType": "n8n-nodes-base.httpRequest",
    "nodeVersion": 4.2,
    "itemIndex": 0,
    "time": "5/20/2025, 3:32:49 PM",
    "n8nVersion": "1.92.2 (Self Hosted)",
    "binaryDataMode": "default",
    "stackTrace": [
      "NodeOperationError: JSON parameter needs to be valid JSON",
      "    at ExecuteContext.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/nodes/HttpRequest/V3/HttpRequestV3.node.ts:355:15)",
      "    at WorkflowExecute.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1172:32)",
      "    at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1521:38",
      "    at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:2085:11"
    ]
  }
}

Information on n8n setup:

  • n8n version: 1.92.2
  • Database (default: SQLite)
  • n8n EXECUTIONS_PROCESS setting (default: own, main)
  • Running n8n via npm
  • Operating system: macOS Sonoma 14.7.4

The value of $json.prompt appears to be invalid JSON.
Try to use an online JSON validator to check the format of your request body.

Common issues include unescaped characters (like quotes "), line breaks, or incorrect syntax.

1 Like

Hi, the issue you’re experiencing in your case is due to the prompt output from the code node containing symbols that invalidate the JSON. Try using this expression in your request body:

{
    "contents": [{
        "parts": [{
            "text": "{{ $json.prompt.replace(/"/g, '\\"').replace(/\n/g, '\\n') }}"
        }]
    }]
}

Hello @sanjaii_vijayakumar

This is a common issue,

Could you please use JSON.stringify() and modify the JSON body to:

{
    "contents": [{
        "parts": [{
            "text": {{ JSON.stringify( $json.prompt ) }}
        }]
    }]
}

Thank you. I took care of it and now it works