"JSON Parameter Needs to Be Valid JSON" Error in HTTP Request Node with ChatGPT Integration

Hi n8n community,

I’m working on a workflow to process emails for beauty salon appointments, and I’m stuck on an error in the HTTP Request node: “JSON parameter needs to be valid JSON.” I’d really appreciate any help!

My setup uses n8n with Postmark, ChatGPT 3.5, and Supabase. The workflow:

  1. A Webhook node receives emails from Postmark (e.g., to [email protected]).
  2. An HTTP Request node sends the email to ChatGPT to extract details (client name, service, date, etc.) as JSON.
  3. A Code node processes the response, and a Switch node routes based on appointment type (new, update, or cancel).
  4. Supabase nodes store the data.

The error happens when testing this email:
To: [email protected]
Body: Hola, Antonio Gomez quiere una cita para un corte de pelo el 12 de junio de 2025 a las 17:00. Su número es 123456789.

I think Spanish characters (like “ó” or “é”) in the email body are breaking the JSON in the HTTP Request node. Here’s the node’s setup:

{
“method”: “POST”,
“url”: “https://api.openai.com/v1/chat/completions”,
“authentication”: “predefinedCredentialType”,
“nodeCredentialType”: “openAiApi”,
“sendHeaders”: true,
“specifyHeaders”: “json”,
“jsonHeaders”: “{"Content-Type": "application/json"}”,
“sendBody”: true,
“specifyBody”: “json”,
“jsonBody”: “{\n "model": "gpt-3.5-turbo",\n "messages": [\n {\n "role": "system",\n "content": "Eres un asistente experto en analizar correos electrónicos de citas… [prompt to extract JSON with fields like codigo_centro, nombre, telefono, etc.]"\n },\n {\n "role": "user",\n "content": "Destinatario (To): {{ $node[‘Webhook’].json.body.To || ‘unknown’ }}\nCuerpo del correo: {{ $node[‘Webhook’].json.body.TextBody || $node[‘Webhook’].json.body.HtmlBody || ‘No body available’ }}"\n }\n ],\n "temperature": 0.3,\n "max_tokens": 500\n}”
}

What I’ve tried:

Validated the JSON in a linter (looks fine without dynamic data).
Removed accents (e.g., “cita” to “cita”), which sometimes works, but real emails will have Spanish characters.
Tested a simpler email, but special characters still cause the error.
Questions:

How do I handle Spanish characters in the email body to avoid JSON errors?
Should I add a Code node to clean the Webhook output before ChatGPT?
Any tips for n8n + OpenAI API to prevent JSON issues?

Happy to share more details if needed. Thanksl.

n8n: Hosted on AWS ECS Fargate (n8nio/n8n:1.0.0).
Webhook URL: http://52.212.47.51:5678/postmark-inbound.

Hey @recordatorioswhats ,

I totally understand why you are getting this error, we can resolve the error that you having.

but before that I would suggest you to use n8n’s pre built node to make an api call to openai, it will be a lot easier for you to work with this node.

Just try this and let me know if it works for you.

but still if you want that you want to make the call via http node, than please keep a note of this..
in json format we cannot have line breaks, if we add them, than it will start showing invalid json.

So why it is showing invalid json is due to fact that the html body you are referencing from the last node must have line break, different paragraphs.
that’s why we have to convert all the inputs to json string so that it should work .

Copy the below and use it inside the content of http code node.

Destinatario (To): {{ $node["Webhook"].json.body.To || "unknown" }}Cuerpo del correo: {{ $node["Webhook"].json.body.TextBody.toJsonString() || $node["Webhook"].json.body.HtmlBody.toJsonString() || "No body available" }}
2 Likes

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