<p><img class="alignnone size-full wp-image-4371" src="https://flowgenius.in/wp-content/uploads/2026/01/Child-3-Cluster-9.png" alt="" /></p>
<p style="text-align: center;">Step by Step Guide to solve n8n HTTP Request Node Invalid JSON Response Error</p>
<p> </p>
<hr />
<p> </p>
<p style="margin-bottom: 2em; line-height: 1.9;"><strong>Who this is for:</strong> n8n workflow creators who receive “Invalid JSON response” errors from the HTTP Request node and need a reliable, production‑ready fix. <strong>We cover this in detail in the</strong> <a href="https://flowgenius.in/n8n-node-errors-troubleshooting/">n8n Node Specific Errors Guide.</a></p>
<div style="margin: 55px 0;"></div>
<h2 style="margin-bottom: 45px; line-height: 1.3;">Quick Diagnosis: Fix the error in seconds</h2>
<ol style="margin-bottom: 1.7em; line-height: 1.9;">
<li>Verify the endpoint really returns JSON (browser or <code>curl</code>).</li>
<li>Temporarily set <strong>Response Format</strong> → <strong>String</strong> in the HTTP Request node.</li>
<li>Inspect the raw payload for HTML, extra characters, or a BOM.</li>
<li>If the payload is valid JSON, switch <strong>Response Format</strong> back to <strong>JSON</strong>.</li>
<li>If it isn’t JSON, add a <strong>Set → JSON Parse</strong> or <strong>Function</strong> node to transform the data.</li>
</ol>
<p style="margin-bottom: 2em; line-height: 1.9;">*Copy the checklist at the end of the article to your workflow and the error disappears.*</p>
<div style="margin: 55px 0;"></div>
<h2 style="margin-bottom: 45px; line-height: 1.3;">1. Why the “Invalid JSON response” error appears</h2>
<p><strong>If you encounter any</strong> <a href="/n8n-http-request-node-error-401">n8n http request node error 401</a><strong> resolve them before continuing with the setup.</strong></p>
<p style="margin-bottom: 2em; line-height: 1.9;"><strong>Root causes</strong> and how n8n detects them:</p>
<table style="border-collapse: collapse; width: 100%; margin-bottom: 2em;">
<thead>
<tr>
<th style="border: 1px solid #e0e0e0; padding: 13px;">Root Cause</th>
<th style="border: 1px solid #e0e0e0; padding: 13px;">Detection</th>
</tr>
</thead>
<tbody>
<tr>
<td style="border: 1px solid #e0e0e0; padding: 13px;">Non‑JSON payload (HTML error page, plain text, CSV)</td>
<td style="border: 1px solid #e0e0e0; padding: 13px;">`JSON.parse()` throws a <code>SyntaxError</code>.</td>
</tr>
<tr>
<td style="border: 1px solid #e0e0e0; padding: 13px;">BOM / invisible characters before <code>{</code> or <code>[</code></td>
<td style="border: 1px solid #e0e0e0; padding: 13px;">Parsing fails despite JSON‑like appearance.</td>
</tr>
<tr>
<td style="border: 1px solid #e0e0e0; padding: 13px;">Wrong <code>Content‑Type</code> header (e.g., <code>text/html</code>)</td>
<td style="border: 1px solid #e0e0e0; padding: 13px;">Node defaults to “String” and later tries to parse.</td>
</tr>
<tr>
<td style="border: 1px solid #e0e0e0; padding: 13px;">Payload > 10 MB (default limit)</td>
<td style="border: 1px solid #e0e0e0; padding: 13px;">n8n aborts parsing to protect memory.</td>
</tr>
<tr>
<td style="border: 1px solid #e0e0e0; padding: 13px;">Server‑side compression not decoded (gzip)</td>
<td style="border: 1px solid #e0e0e0; padding: 13px;">Binary gibberish is fed to <code>JSON.parse()</code>.</td>
</tr>
</tbody>
</table>
<p style="margin-bottom: 2em; line-height: 1.9;"><em>EEFA note:</em> Disabling strict JSON validation (<code>Continue On Fail</code>) only masks the problem and is not a production‑grade fix.</p>
<div style="margin: 55px 0;"></div>
<h2 style="margin-bottom: 45px; line-height: 1.3;">2. Step‑by‑step debugging workflow</h2>
<p><strong>If you encounter any</strong> <a href="/n8n-http-request-node-timeout">n8n http request node timeout</a><strong> resolve them before continuing with the setup.</strong></p>
<h3 style="margin-bottom: 45px; line-height: 1.3;">2.1 Capture the raw response</h3>
<p style="margin-bottom: 2em; line-height: 1.9;"><strong>Purpose:</strong> See exactly what the API returns before n8n attempts to parse it.</p>
<ol style="margin-bottom: 1.7em; line-height: 1.9;">
<li>Open the **HTTP Request** node.</li>
<li>Set **Response Format** → **String** (temporary).</li>
<li>Run the node.</li>
<li>In **Execution → Output**, copy the **Body** field.</li>
</ol>
<p style="margin-bottom: 2em; line-height: 1.9;"><strong>Tip:</strong> If the body starts with <code><!DOCTYPE html></code> or contains <code><html></code>, you’re looking at an HTML error page (e.g., 404, 500).</p>
<h3 style="margin-bottom: 45px; line-height: 1.3;">2.2 Verify JSON validity with <code>curl</code></h3>
<pre style="background: #fafafa; padding: 20px; border: 1px solid #e0e0e0; overflow: auto;">curl -s -H "Accept: application/json" "https://api.example.com/data" |
jq . > /dev/null && echo "Valid JSON" || echo "Invalid JSON"</pre>
<p style="margin-bottom: 2em; line-height: 1.9;"><strong>Result:</strong></p>
<ul style="margin-bottom: 1.7em; line-height: 1.9;">
<li><code>Valid JSON</code> → the endpoint returns well‑formed JSON.</li>
<li><code>Invalid JSON</code> → inspect the raw output for the issue.</li>
</ul>
<h3 style="margin-bottom: 45px; line-height: 1.3;">2.3 Common fixes</h3>
<table style="border-collapse: collapse; width: 100%; margin-bottom: 2em;">
<thead>
<tr>
<th style="border: 1px solid #e0e0e0; padding: 13px;">Issue</th>
<th style="border: 1px solid #e0e0e0; padding: 13px;">Fix</th>
</tr>
</thead>
<tbody>
<tr>
<td style="border: 1px solid #e0e0e0; padding: 13px;">HTML error page</td>
<td style="border: 1px solid #e0e0e0; padding: 13px;">Check URL, auth, or query parameters. Use an **If** node to branch on non‑2xx status codes.</td>
</tr>
<tr>
<td style="border: 1px solid #e0e0e0; padding: 13px;">BOM / whitespace</td>
<td style="border: 1px solid #e0e0e0; padding: 13px;">Add a **Function** node to strip it (see snippet below).</td>
</tr>
<tr>
<td style="border: 1px solid #e0e0e0; padding: 13px;">Wrong <code>Content‑Type</code></td>
<td style="border: 1px solid #e0e0e0; padding: 13px;">Set header <code>Accept: application/json</code> and keep **Response Format** = **JSON**.</td>
</tr>
<tr>
<td style="border: 1px solid #e0e0e0; padding: 13px;">Compressed payload</td>
<td style="border: 1px solid #e0e0e0; padding: 13px;">Enable **Decompress response** or add header <code>Accept‑Encoding: gzip, deflate</code>.</td>
</tr>
<tr>
<td style="border: 1px solid #e0e0e0; padding: 13px;">Payload too large</td>
<td style="border: 1px solid #e0e0e0; padding: 13px;">Increase **Maximum response size** (monitor memory usage).</td>
</tr>
</tbody>
</table>
<h4 style="margin-bottom: 45px; line-height: 1.3;">Stripping BOM / whitespace</h4>
<pre style="background: #fafafa; padding: 20px; border: 1px solid #e0e0e0; overflow: auto;">// Function node: clean the raw string before parsing
const raw = $json["body"];
const cleaned = raw.replace(/^\uFEFF/, "").trim();
return { json: JSON.parse(cleaned) };</pre>
<h3 style="margin-bottom: 45px; line-height: 1.3;">2.4 Re‑enable proper JSON parsing</h3>
<ol style="margin-bottom: 1.7em; line-height: 1.9;">
<li>After confirming the payload is clean JSON, switch **Response Format** back to **JSON**.</li>
<li>Run the node again – the error should disappear.</li>
</ol>
<p style="margin-bottom: 2em; line-height: 1.9;">If the API cannot return JSON (e.g., CSV), keep **Response Format** as **String** and add a **Function** or **CSV Parse** node to convert the data for downstream steps.</p>
<div style="margin: 55px 0;"></div>
<h2 style="margin-bottom: 45px; line-height: 1.3;">3. Real‑world example: Fixing a mis‑configured third‑party API</h2>
<h3 style="margin-bottom: 45px; line-height: 1.3;">3.1 Problem description</h3>
<p style="margin-bottom: 2em; line-height: 1.9;">A workflow that pulls product data from <code>https://api.shopify.com/v1/products.json</code> fails with:</p>
<pre style="background: #fafafa; padding: 20px; border: 1px solid #e0e0e0; overflow: auto;">Error: Invalid JSON response</pre>
<p style="margin-bottom: 2em; line-height: 1.9;">The captured raw payload (with “Response Format: String”) begins with:</p>
<pre style="background: #fafafa; padding: 20px; border: 1px solid #e0e0e0; overflow: auto;"><!DOCTYPE html>
<html>
<head><title>401 Unauthorized</title></head>
...
</pre>
<h3 style="margin-bottom: 45px; line-height: 1.3;">3.2 Solution steps</h3>
<ol style="margin-bottom: 1.7em; line-height: 1.9;">
<li>Add an “If” node to test <code>{{$node["HTTP Request"].statusCode}}</code> for <code>200</code>.</li>
<li>Insert a “Set” node before the request to include the required header.</li>
</ol>
<h4 style="margin-bottom: 45px; line-height: 1.3;">Adding the authentication header</h4>
<pre style="background: #fafafa; padding: 20px; border: 1px solid #e0e0e0; overflow: auto;">{
"parameters": {
"url": "https://api.shopify.com/v1/products.json",
"method": "GET",
"responseFormat": "JSON",
"headerParametersUi": {
"parameter": [
{
"name": "X-Shopify-Access-Token",
"value": "{{$env.SHOPIFY_TOKEN}}"
}
]
}
},
"name": "HTTP Request",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 2,
"position": [400, 300]
}</pre>
<p style="margin-bottom: 2em; line-height: 1.9;">Re‑run the workflow – the node now returns proper JSON and the error disappears.</p>
<p style="margin-bottom: 2em; line-height: 1.9;"><em>EEFA warning:</em> Storing API keys in plain text inside a workflow is insecure. Use **n8n credentials** or **environment variables** (<code>{{$env.VAR_NAME}}</code>).</p>
<div style="margin: 55px 0;"></div>
<h2 style="margin-bottom: 45px; line-height: 1.3;">4. Checklist – Prevent “Invalid JSON response” before it happens</h2>
<p><strong>If you encounter any </strong><a href="/n8n-webhook-node-missing-signature">n8n webhook node missing signature </a><strong>resolve them before continuing.</strong></p>
<ul style="margin-bottom: 1.7em; line-height: 1.9;">
<li>[ ] Validate endpoint with a tool (Postman, curl) – ensure it returns JSON.</li>
<li>[ ] Set proper <code>Accept</code> header (<code>application/json</code>).</li>
<li>[ ] Confirm correct HTTP method (GET vs POST).</li>
<li>[ ] Verify authentication (API keys, OAuth tokens) – 401/403 often return HTML.</li>
<li>[ ] Enable “Decompress response” if the server sends gzip.</li>
<li>[ ] Use **Response Format** = **JSON** only after confirming payload is JSON.</li>
<li>[ ] Add error‑branching (<code>If</code> node) for non‑2xx status codes.</li>
<li>[ ] Log raw payload (String mode) during development.</li>
</ul>
<div style="margin: 55px 0;"></div>
<h2 style="margin-bottom: 45px; line-height: 1.3;">5. Advanced – Handling APIs that intermittently return malformed JSON</h2>
<p style="margin-bottom: 2em; line-height: 1.9;">Some legacy APIs prepend an anti‑XSS prefix like <code>)]}',</code> before the JSON:</p>
<pre style="background: #fafafa; padding: 20px; border: 1px solid #e0e0e0; overflow: auto;">)]}',{"data":{...}}</pre>
<h3 style="margin-bottom: 45px; line-height: 1.3;">Fix with a Function node</h3>
<pre style="background: #fafafa; padding: 20px; border: 1px solid #e0e0e0; overflow: auto;">// Remove the prefix if present
const raw = $json["body"];
const cleaned = raw.replace(/^\\)\\]\\}',/, "");
return { json: JSON.parse(cleaned) };</pre>
<p style="margin-bottom: 2em; line-height: 1.9;">Place this **Function** node **after** the HTTP Request (set to **String**) and **before** any downstream node that expects JSON.</p>
<p style="margin-bottom: 2em; line-height: 1.9;"><em>EEFA tip:</em> Wrap the parsing in a <code>try / catch</code> block and route failures to a dedicated **Error Handling** workflow to avoid silent data loss.</p>
<div style="margin: 55px 0;"></div>
<h2 style="margin-bottom: 45px; line-height: 1.3;">Conclusion</h2>
<p style="margin-bottom: 2em; line-height: 1.9;">The “Invalid JSON response” error is almost always traceable to a mismatch between what the API actually returns and what n8n expects. By capturing the raw payload, verifying JSON validity, correcting headers or authentication, and handling edge cases (BOM, compression, size limits) with small, focused nodes, you can eliminate the error and keep your workflows robust in production. Use the checklist to pre‑empt issues, and remember to keep secrets out of the workflow definition for security.</p>

Step by Step Guide to solve n8n HTTP Request Node Invalid JSON Response Error
Who this is for: n8n workflow creators who receive “Invalid JSON response” errors from the HTTP Request node and need a reliable, production‑ready fix. We cover this in detail in the n8n Node Specific Errors Guide.
Quick Diagnosis: Fix the error in seconds
- Verify the endpoint really returns JSON (browser or
curl).
- Temporarily set Response Format → String in the HTTP Request node.
- Inspect the raw payload for HTML, extra characters, or a BOM.
- If the payload is valid JSON, switch Response Format back to JSON.
- If it isn’t JSON, add a Set → JSON Parse or Function node to transform the data.
*Copy the checklist at the end of the article to your workflow and the error disappears.*
1. Why the “Invalid JSON response” error appears
If you encounter any n8n http request node error 401 resolve them before continuing with the setup.
Root causes and how n8n detects them:
| Root Cause |
Detection |
| Non‑JSON payload (HTML error page, plain text, CSV) |
`JSON.parse()` throws a SyntaxError. |
BOM / invisible characters before { or [ |
Parsing fails despite JSON‑like appearance. |
Wrong Content‑Type header (e.g., text/html) |
Node defaults to “String” and later tries to parse. |
| Payload > 10 MB (default limit) |
n8n aborts parsing to protect memory. |
| Server‑side compression not decoded (gzip) |
Binary gibberish is fed to JSON.parse(). |
EEFA note: Disabling strict JSON validation (Continue On Fail) only masks the problem and is not a production‑grade fix.
2. Step‑by‑step debugging workflow
If you encounter any n8n http request node timeout resolve them before continuing with the setup.
2.1 Capture the raw response
Purpose: See exactly what the API returns before n8n attempts to parse it.
- Open the **HTTP Request** node.
- Set **Response Format** → **String** (temporary).
- Run the node.
- In **Execution → Output**, copy the **Body** field.
Tip: If the body starts with <!DOCTYPE html> or contains <html>, you’re looking at an HTML error page (e.g., 404, 500).
2.2 Verify JSON validity with curl
curl -s -H "Accept: application/json" "https://api.example.com/data" |
jq . > /dev/null && echo "Valid JSON" || echo "Invalid JSON"
Result:
Valid JSON → the endpoint returns well‑formed JSON.
Invalid JSON → inspect the raw output for the issue.
2.3 Common fixes
| Issue |
Fix |
| HTML error page |
Check URL, auth, or query parameters. Use an **If** node to branch on non‑2xx status codes. |
| BOM / whitespace |
Add a **Function** node to strip it (see snippet below). |
Wrong Content‑Type |
Set header Accept: application/json and keep **Response Format** = **JSON**. |
| Compressed payload |
Enable **Decompress response** or add header Accept‑Encoding: gzip, deflate. |
| Payload too large |
Increase **Maximum response size** (monitor memory usage). |
Stripping BOM / whitespace
// Function node: clean the raw string before parsing
const raw = $json["body"];
const cleaned = raw.replace(/^\uFEFF/, "").trim();
return { json: JSON.parse(cleaned) };
2.4 Re‑enable proper JSON parsing
- After confirming the payload is clean JSON, switch **Response Format** back to **JSON**.
- Run the node again – the error should disappear.
If the API cannot return JSON (e.g., CSV), keep **Response Format** as **String** and add a **Function** or **CSV Parse** node to convert the data for downstream steps.
3. Real‑world example: Fixing a mis‑configured third‑party API
3.1 Problem description
A workflow that pulls product data from https://api.shopify.com/v1/products.json fails with:
Error: Invalid JSON response
The captured raw payload (with “Response Format: String”) begins with:
<!DOCTYPE html>
<html>
<head><title>401 Unauthorized</title></head>
...
3.2 Solution steps
- Add an “If” node to test
{{$node["HTTP Request"].statusCode}} for 200.
- Insert a “Set” node before the request to include the required header.
Adding the authentication header
{
"parameters": {
"url": "https://api.shopify.com/v1/products.json",
"method": "GET",
"responseFormat": "JSON",
"headerParametersUi": {
"parameter": [
{
"name": "X-Shopify-Access-Token",
"value": "{{$env.SHOPIFY_TOKEN}}"
}
]
}
},
"name": "HTTP Request",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 2,
"position": [400, 300]
}
Re‑run the workflow – the node now returns proper JSON and the error disappears.
EEFA warning: Storing API keys in plain text inside a workflow is insecure. Use **n8n credentials** or **environment variables** ({{$env.VAR_NAME}}).
4. Checklist – Prevent “Invalid JSON response” before it happens
If you encounter any n8n webhook node missing signature resolve them before continuing.
- [ ] Validate endpoint with a tool (Postman, curl) – ensure it returns JSON.
- [ ] Set proper
Accept header (application/json).
- [ ] Confirm correct HTTP method (GET vs POST).
- [ ] Verify authentication (API keys, OAuth tokens) – 401/403 often return HTML.
- [ ] Enable “Decompress response” if the server sends gzip.
- [ ] Use **Response Format** = **JSON** only after confirming payload is JSON.
- [ ] Add error‑branching (
If node) for non‑2xx status codes.
- [ ] Log raw payload (String mode) during development.
5. Advanced – Handling APIs that intermittently return malformed JSON
Some legacy APIs prepend an anti‑XSS prefix like )]}', before the JSON:
)]}',{"data":{...}}
Fix with a Function node
// Remove the prefix if present
const raw = $json["body"];
const cleaned = raw.replace(/^\\)\\]\\}',/, "");
return { json: JSON.parse(cleaned) };
Place this **Function** node **after** the HTTP Request (set to **String**) and **before** any downstream node that expects JSON.
EEFA tip: Wrap the parsing in a try / catch block and route failures to a dedicated **Error Handling** workflow to avoid silent data loss.
Conclusion
The “Invalid JSON response” error is almost always traceable to a mismatch between what the API actually returns and what n8n expects. By capturing the raw payload, verifying JSON validity, correcting headers or authentication, and handling edge cases (BOM, compression, size limits) with small, focused nodes, you can eliminate the error and keep your workflows robust in production. Use the checklist to pre‑empt issues, and remember to keep secrets out of the workflow definition for security.