Claude JSON Fences Break n8n Code Nodes Silently — and How to Fix It
You ask Claude to generate a JSON object for an n8n Code node. You paste the output. The workflow runs. No errors appear. But the data is wrong, or downstream nodes receive nothing.
The cause is almost always the same: Claude wrapped the JSON in a code fence, and you pasted the fence markers along with the content.
What Happens
Claude frequently formats JSON output like this:
```json
{
"name": "test",
"value": 42
}
In a chat interface, this renders cleanly as a code block. The triple backtick fence and `json` language tag are display formatting — they are not part of the JSON.
When you paste this directly into an n8n Code node as a JavaScript expression, you get:
```javascript
```json
{
"name": "test",
"value": 42
}
That is not valid JavaScript. The triple backticks are not recognized as string delimiters. n8n's JavaScript runtime parses this and either:
- Throws a syntax error (which you see)
- Silently swallows the error and returns empty output (which you do not see)
The silent failure variant is the dangerous one. n8n's Code node in some configurations will execute the partial code and return an empty array or undefined without surfacing an error in the execution log.
## Why It Is Hard to Diagnose
The silence makes this hard to find because:
1. The execution shows "success" in the log
2. The Code node's output panel shows an empty object rather than an error
3. The workflow continues to the next node with no data
4. Downstream nodes process the empty input and may also succeed with empty output
By the time you notice something is wrong, the failure is several nodes deep and the Code node output panel is not the first place you look.
## Three Ways to Prevent It
**Option 1: Strip the fences manually.** Before pasting, remove the opening ` ```json ` and closing ` ``` ` markers. This is the simplest fix but requires remembering to do it every time.
**Option 2: Prompt Claude to not use fences.** Add explicit instructions to your Claude prompt:
Return only the raw JavaScript code with no markdown formatting, no code fences, and no explanation. The response should be valid JavaScript that can be pasted directly into an n8n Code node.
This works reliably for most cases. Claude follows formatting instructions when they are explicit.
**Option 3: Validate before pasting.** Paste the Claude output into a browser console or a JavaScript validator first. If it throws a SyntaxError, you have fence markers or other non-JavaScript formatting. Fix it before pasting into n8n.
## The Broader Pattern: LLM Code Generation in n8n
The JSON fence issue is an instance of a broader pattern: when using LLMs to generate n8n code, always verify that the output is clean JavaScript before pasting.
Common issues beyond JSON fences:
- **TypeScript syntax** in a JavaScript-only Code node (type annotations, `interface` declarations)
- **ES module syntax** (`import`/`export`) that n8n's runtime does not support
- **Node.js built-in modules** like `fs` or `path` that are not available in n8n's sandboxed execution
- **Async/await patterns** that work in some n8n versions but not others
A fast verification workflow: paste Claude's output into the n8n Code node, add a simple `console.log($input.all())` at the end, and run a test execution. If the console output appears in the execution log, your code is running. If it does not, you have a parse error before the first line executes.
## Detecting It After the Fact
If you suspect this issue in an existing workflow:
1. Open the Code node
2. Look at the first line — if you see ` ``` ` or `~~~` characters, you have fence markers
3. Check for any line that starts with a backtick not inside a string literal
4. Run the node in isolation and check both the output data and the browser console for JavaScript errors
Once you have seen this pattern once, you will recognize the silent-empty-output signature immediately. The first instinct after empty Code node output should always be: check for fence markers or invalid JavaScript syntax.
## One More: The JSON.parse Trap
Related to the fence issue: when Claude generates `JSON.parse(...)` calls, it sometimes wraps the string argument in backtick template literals that contain fence formatting. This produces code like:
```javascript
const data = JSON.parse(`
```json
{"key": "value"}
`);
That also fails silently. The JSON.parse call receives a string with literal backtick-json markers, the parse fails, and if you do not have try/catch around it, n8n may not surface the error.
Fix: make the Claude prompt explicit about not using code fences inside string values, or always wrap JSON.parse calls in try/catch to surface parse errors.