{"record":{"id":"99ac81bc16472e32","repo":"n8n-io/n8n","slug":"smartjoin-expected-two-string-args-e-g-smart","errorCode":null,"errorMessage":"smartJoin(): expected two string args, e.g. .smartJoin(\"name\", \"value\")","messagePattern":"smartJoin\\(\\): expected two string args, e\\.g\\. \\.smartJoin\\(\"name\", \"value\"\\)","errorType":"exception","errorClass":"ExpressionExtensionError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/expression-runtime/src/extensions/array-extensions.ts","lineNumber":162,"sourceCode":"function compact(value: unknown[]): unknown[] {\n\treturn value\n\t\t.filter((v) => {\n\t\t\tif (v && typeof v === 'object' && Object.keys(v).length === 0) return false;\n\n\t\t\treturn v !== null && v !== undefined && v !== 'nil' && v !== '';\n\t\t})\n\t\t.map((v) => {\n\t\t\tif (typeof v === 'object' && v !== null) {\n\t\t\t\treturn oCompact(v);\n\t\t\t}\n\t\t\treturn v;\n\t\t});\n}\n\nfunction smartJoin(value: unknown[], extraArgs: string[]): object {\n\tconst [keyField, valueField] = extraArgs;\n\tif (!keyField || !valueField || typeof keyField !== 'string' || typeof valueField !== 'string') {\n\t\tthrow new ExpressionExtensionError(\n\t\t\t'smartJoin(): expected two string args, e.g. .smartJoin(\"name\", \"value\")',\n\t\t);\n\t}\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-return\n\treturn value.reduce<any>((o, v) => {\n\t\tif (typeof v === 'object' && v !== null && keyField in v && valueField in v) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any\n\t\t\to[(v as any)[keyField]] = (v as any)[valueField];\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn o;\n\t}, {});\n}\n\nfunction chunk(value: unknown[], extraArgs: number[]) {\n\tconst [chunkSize] = extraArgs;\n\tif (typeof chunkSize !== 'number' || chunkSize === 0) {\n\t\tthrow new ExpressionExtensionError('chunk(): expected non-zero numeric arg, e.g. .chunk(5)');","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/expression-runtime/src/extensions/array-extensions.ts#L144-L180","documentation":"Thrown as ExpressionExtensionError by the .smartJoin() array extension when its two arguments (keyField, valueField) are missing or not strings. smartJoin builds a single object from an array of objects, using keyField as the key-name source and valueField as the value source for each element. Both must be non-empty strings; otherwise the function cannot know which fields to read.","triggerScenarios":"Calling .smartJoin() with zero arguments, one argument, or non-string arguments (e.g. a number or object). Example: [{field:'age',value:2}].smartJoin() (missing second arg) or .smartJoin('field', 42) (second arg not a string).","commonSituations":"Forgetting the second argument. Passing a variable that resolved to undefined/null instead of a field-name string. Mismatching the field names the objects actually contain.","solutions":["Pass exactly two string arguments naming the key and value fields: .smartJoin('name', 'value').","Confirm the objects in the array actually contain both fields.","If the field names are dynamic, guard that both are strings before calling.","See the doc example: [{field:'age',value:2},{field:'city',value:'Berlin'}].smartJoin('field','value')."],"exampleFix":"// before — missing second argument\n{{ $json.rows.smartJoin('field') }}\n// after — both field names as strings\n{{ $json.rows.smartJoin('field', 'value') }}","handlingStrategy":"validation","validationCode":"function smartJoinSafe(arr, keyField, valueField) {\n  if (typeof keyField !== 'string' || typeof valueField !== 'string' || !keyField || !valueField) {\n    throw new TypeError('smartJoin requires two non-empty string field names');\n  }\n  // ...proceed\n}","typeGuard":"function areSmartJoinArgsValid(args) {\n  return Array.isArray(args) && typeof args[0] === 'string' && typeof args[1] === 'string' && args[0].length > 0 && args[1].length > 0;\n}","tryCatchPattern":"try {\n  result = arr.smartJoin('name', 'value');\n} catch (e) {\n  if (e.name === 'ExpressionExtensionError' && /smartJoin/i.test(e.message)) {\n    // pass exactly two string field names\n  }\n}","preventionTips":["Always pass two non-empty string arguments: .smartJoin('keyField', 'valueField').","Confirm the objects in the array contain both named fields.","Guard dynamic field names with typeof checks before calling."],"tags":["expression-runtime","array-extensions","smartjoin","argument-validation"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}