n8n-io/n8n · error · Error
nodeJson() requires a node or node name.
Error message
nodeJson() requires a node or node name.
What it means
nodeJson() resolves the node reference to a name via resolveNodeName() (the string itself, or node.name for a node instance). If that resolved name is falsy (empty string or undefined), this error fires because the generated $('...') reference would be invalid.
Source
Thrown at packages/@n8n/workflow-sdk/src/expression/index.ts:121
/**
* Build an expression that references JSON data from a specific node by name.
*
* Prefer this over `$json` when a value comes from an AI subnode, a fan-in
* branch, or any node other than the immediate main-flow predecessor.
*
* @example
* ```typescript
* nodeJson(telegramTrigger, 'message.chat.id')
* // "={{ $('Telegram Trigger').item.json.message.chat.id }}"
*
* nodeJson('Set User', ['profile', 'user-id'])
* // "={{ $('Set User').item.json.profile[\"user-id\"] }}"
* ```
*/
export function nodeJson(node: NodeJsonReference, path: string | readonly string[]): string {
const nodeName = resolveNodeName(node);
if (!nodeName) {
throw new Error('nodeJson() requires a node or node name.');
}
const pathExpression = normalizePath(path).map(formatPathSegment).join('');
return `={{ $('${escapeNodeName(nodeName)}').item.json${pathExpression} }}`;
}
// =============================================================================
// $fromAI Expression Generator
// =============================================================================
/**
* Sanitize a key for use in $fromAI expression.
* Keys must be 1-64 characters, alphanumeric with underscores and hyphens only.
*
* @param key - The original key string
* @returns Sanitized key that meets $fromAI requirements
*/
function sanitizeFromAIKey(key: string): string {View on GitHub (pinned to 5ac6606e81)
Solutions
- Pass a non-empty node name string, e.g. nodeJson('Set User', 'id').
- If passing a node instance, ensure it was created with a non-empty name.
- Validate the node name is truthy before calling nodeJson().
Example fix
// before
const ref = nodeJson('', 'id');
// after
const ref = nodeJson('Set User', 'id'); Defensive patterns
Strategy: validation
Validate before calling
// Ensure the node resolves to a non-empty name before calling nodeJson().
const name = typeof node === 'string' ? node : node?.name;
if (!name) throw new Error('nodeJson needs a non-empty node name');
const ref = nodeJson(node, path); Type guard
function hasNodeName(n: unknown): n is { name: string } | string {
return typeof n === 'string' ? n.length > 0 : !!n && typeof (n as any).name === 'string' && (n as any).name.length > 0;
} Prevention
- Pass a concrete non-empty node name string.
- When passing a node instance, ensure it was constructed with a name.
- Validate dynamic node names before referencing them.
When it happens
Trigger: nodeJson('', 'id'), nodeJson({ name: '' }, 'id'), nodeJson(undefined as any, 'id'), or passing a node instance whose name property is empty.
Common situations: Node name sourced from dynamic/empty data; referencing a node by an unset variable; LLM uses a placeholder node name.
Related errors
- nodeJson() requires a non-empty JSON path.
- expr(newCredential('${value.name}')) is invalid. Use newCred
- expr() requires a string argument, but received ${typeof val
- topK must be an integer >= 1, got ${k}
- intersection(): expected array arg, e.g. .intersection([1, 2
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/c21f3d52b9d62374.
Report an issue: GitHub.