Fixing n8n "Node Execution Failed: JSON Parse Error" (Step-by-Step Fix)

Running into a runtime halt in your automated workflow can be frustrating, especially when encountering the infamous n8n "Node Execution Failed: JSON Parse Error" message. This issue typically occurs when an n8n node attempts to evaluate raw payload data, LLM AI responses, or HTTP API bodies that contain malformed syntax, unescaped quotation marks, or trailing commas. Applying a reliable n8n json parse error fix ensures your automation pipeline handles unexpected string structures gracefully without failing in production.

⚠️ Why Does JSON Parsing Fail in n8n?

JSON requires strict syntax rules: key names must be wrapped in double quotes, strings cannot contain unescaped newline characters, and trailing commas are strictly prohibited. AI models (like OpenAI or DeepSeek) or raw webhooks frequently return markdown-wrapped JSON strings (e.g., ```json ... ```) which causes native JavaScript JSON.parse() methods to throw an error.

Prerequisites for Troubleshooting JSON Errors in n8n

Before applying the fixes outlined below, ensure you have the following prerequisites ready:

  • Active n8n Instance: Access to an operational self-hosted Docker, VPS, or n8n Cloud deployment.
  • Failed Execution Logs: Access to the Executions tab in n8n to inspect the exact input payload triggering the crash.
  • Basic JavaScript Familiarity: Understanding how string manipulation works inside n8n Code nodes.

Step-by-Step Blueprint: Applying the n8n JSON Parse Error Fix

Step 1: Identify the Malformed Input Payload

First, open your n8n workflow canvas and navigate to the node raising the error (commonly a Code Node, Edit Fields (Set) Node, or HTTP Request Node).

  • Switch the node execution view to JSON Output / Input.
  • Inspect the raw string value. Check if double quotes inside text values are unescaped (e.g., {"summary": "He said "Hello""} instead of {"summary": "He said \"Hello\""}).
  • Look for markdown backticks added by AI nodes (e.g., ```json ... ```).

Step 2: Clean and Strip AI Markdown Formatting (Code Node)

If the error originates from an AI Agent node output, insert a Code Node immediately after the AI node to sanitize the output before parsing:

// Clean Raw String and Safe-Parse JSON
let rawText = $input.item.json.response || $input.item.json.text || "";

// 1. Remove markdown code block wrappers
rawText = rawText.replace(/```json/gi, "").replace(/```/g, "").trim();

// 2. Fix unescaped newlines within JSON strings
rawText = rawText.replace(/\n/g, "\\n").replace(/\r/g, "\\r");

let parsedData = {};

try {
  parsedData = JSON.parse(rawText);
} catch (error) {
  // Safe Fallback if parsing still fails
  parsedData = {
    parse_error: true,
    original_text: rawText,
    error_message: error.message
  };
}

return {
  json: parsedData
};

Step 3: Enable Native Error Handling in Node Settings

To prevent your entire workflow from stopping when malformed data passes through, configure the node's built-in error handling:

  • Click on the node throwing the error to open its settings modal.
  • Navigate to the Settings tab at the top right.
  • Change OnError from Stop Workflow to Continue (using error output) or Continue (using fallback output).

Common Causes & Solution Comparison

Root Cause Example Syntax Recommended Fix
Markdown Code Blocks ```json {"status": "ok"} ``` Regex replace backticks prior to JSON.parse().
Unescaped Quotes {"title": "User "Admin""} Escape quotes or enforce JSON Schema Output in LLMs.
Trailing Commas {"a": 1, "b": 2,} Strip trailing commas using JS replace logic.

Importable n8n Safe JSON Parser Workflow Template

Copy the JSON template below and paste it directly into your n8n workflow canvas using Ctrl + V (or Cmd + V) to test an isolated, fail-safe JSON parsing node:

Troubleshooting Related Errors

  • Unexpected Token Error in JSON: Verify that your API source is returning application/json header content type instead of text/html (such as a 404 or 500 error page formatted in HTML).
  • Circular Reference Error: Occurs when trying to stringify an object containing self-referencing variables. Use a custom replacer function inside JSON.stringify().

Related Guides & Resources

Enhance your n8n workflow robustness with these related PromptLogic technical guides:

Post a Comment for "Fixing n8n "Node Execution Failed: JSON Parse Error" (Step-by-Step Fix)"