{"record":{"id":"c21f3d52b9d62374","repo":"n8n-io/n8n","slug":"nodejson-requires-a-node-or-node-name","errorCode":null,"errorMessage":"nodeJson() requires a node or node name.","messagePattern":"nodeJson\\(\\) requires a node or node name\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/workflow-sdk/src/expression/index.ts","lineNumber":121,"sourceCode":"/**\n * Build an expression that references JSON data from a specific node by name.\n *\n * Prefer this over `$json` when a value comes from an AI subnode, a fan-in\n * branch, or any node other than the immediate main-flow predecessor.\n *\n * @example\n * ```typescript\n * nodeJson(telegramTrigger, 'message.chat.id')\n * // \"={{ $('Telegram Trigger').item.json.message.chat.id }}\"\n *\n * nodeJson('Set User', ['profile', 'user-id'])\n * // \"={{ $('Set User').item.json.profile[\\\"user-id\\\"] }}\"\n * ```\n */\nexport function nodeJson(node: NodeJsonReference, path: string | readonly string[]): string {\n\tconst nodeName = resolveNodeName(node);\n\tif (!nodeName) {\n\t\tthrow new Error('nodeJson() requires a node or node name.');\n\t}\n\n\tconst pathExpression = normalizePath(path).map(formatPathSegment).join('');\n\treturn `={{ $('${escapeNodeName(nodeName)}').item.json${pathExpression} }}`;\n}\n\n// =============================================================================\n// $fromAI Expression Generator\n// =============================================================================\n\n/**\n * Sanitize a key for use in $fromAI expression.\n * Keys must be 1-64 characters, alphanumeric with underscores and hyphens only.\n *\n * @param key - The original key string\n * @returns Sanitized key that meets $fromAI requirements\n */\nfunction sanitizeFromAIKey(key: string): string {","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/workflow-sdk/src/expression/index.ts#L103-L139","documentation":"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.","triggerScenarios":"nodeJson('', 'id'), nodeJson({ name: '' }, 'id'), nodeJson(undefined as any, 'id'), or passing a node instance whose name property is empty.","commonSituations":"Node name sourced from dynamic/empty data; referencing a node by an unset variable; LLM uses a placeholder node name.","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()."],"exampleFix":"// before\nconst ref = nodeJson('', 'id');\n// after\nconst ref = nodeJson('Set User', 'id');","handlingStrategy":"validation","validationCode":"// Ensure the node resolves to a non-empty name before calling nodeJson().\nconst name = typeof node === 'string' ? node : node?.name;\nif (!name) throw new Error('nodeJson needs a non-empty node name');\nconst ref = nodeJson(node, path);","typeGuard":"function hasNodeName(n: unknown): n is { name: string } | string {\n  return typeof n === 'string' ? n.length > 0 : !!n && typeof (n as any).name === 'string' && (n as any).name.length > 0;\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["expression","validation","sdk","runtime"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}