{"record":{"id":"141ced5433c72bb5","repo":"n8n-io/n8n","slug":"merge-expected-array-arg-e-g-merge-id-1","errorCode":null,"errorMessage":"merge(): expected array arg, e.g. .merge([{ id: 1, otherValue: 3 }])","messagePattern":"merge\\(\\): expected array arg, e\\.g\\. \\.merge\\(\\[(.+?)\\]\\)","errorType":"exception","errorClass":"ExpressionExtensionError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/expression-runtime/src/extensions/array-extensions.ts","lineNumber":250,"sourceCode":"\treturn newObject;\n}\n\nfunction merge(value: unknown[], extraArgs: unknown[][]): unknown {\n\tconst [others] = extraArgs;\n\n\tif (others === undefined) {\n\t\t// If there are no arguments passed, merge all objects within the array\n\t\tconst merged = value.reduce((combined, current) => {\n\t\t\tif (current !== null && typeof current === 'object' && !Array.isArray(current)) {\n\t\t\t\tcombined = mergeObjects(combined as Record<string, unknown>, [current]);\n\t\t\t}\n\t\t\treturn combined;\n\t\t}, {});\n\t\treturn merged;\n\t}\n\n\tif (!Array.isArray(others)) {\n\t\tthrow new ExpressionExtensionError(\n\t\t\t'merge(): expected array arg, e.g. .merge([{ id: 1, otherValue: 3 }])',\n\t\t);\n\t}\n\tconst listLength = value.length > others.length ? value.length : others.length;\n\tlet merged = {};\n\tfor (let i = 0; i < listLength; i++) {\n\t\tif (value[i] !== undefined) {\n\t\t\tif (typeof value[i] === 'object' && typeof others[i] === 'object') {\n\t\t\t\tmerged = Object.assign(\n\t\t\t\t\tmerged,\n\t\t\t\t\tmergeObjects(value[i] as Record<string, unknown>, [others[i]]),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\treturn merged;\n}\n","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/expression-runtime/src/extensions/array-extensions.ts#L232-L268","documentation":"Thrown as ExpressionExtensionError by the .merge() array extension when its argument is present but not an array. merge() merges two object-arrays element-by-element; if called with no argument it instead merges all objects within the array itself. A present-but-non-array argument (e.g. a single object) is invalid because merge iterates by index against the base array.","triggerScenarios":"Calling .merge() with a single object instead of an array of objects: [...].merge({id:1}) instead of [...].merge([{id:1}]). The check `if (!Array.isArray(others))` catches primitives, plain objects, strings, etc.","commonSituations":"Passing a bare object literal when the API expects an array of objects. A template variable that resolves to an object rather than an array. Misreading the doc example and dropping the enclosing brackets.","solutions":["Wrap the argument in an array: .merge([{id:1, otherValue:3}]).","If you want to merge all objects within the array itself, call .merge() with NO argument.","Guard with Array.isArray(arg) before calling.","Match the documented shape exactly: base array + array argument."],"exampleFix":"// before — single object argument\n{{ $json.rows.merge({ id: 1, otherValue: 3 }) }}\n// after — array argument\n{{ $json.rows.merge([{ id: 1, otherValue: 3 }]) }}","handlingStrategy":"type-guard","validationCode":"function mergeSafe(arr, others) {\n  if (others !== undefined && !Array.isArray(others)) throw new TypeError('merge(): expected array arg');\n  // ...proceed with arr.merge(others)\n}","typeGuard":"function isMergeArgValid(others) { return others === undefined || Array.isArray(others); }","tryCatchPattern":"try {\n  result = arr.merge(others);\n} catch (e) {\n  if (e.name === 'ExpressionExtensionError' && /merge.*array/i.test(e.message)) {\n    // wrap the argument in an array: arr.merge([others])\n  }\n}","preventionTips":["Wrap merge arguments in an array: .merge([{id:1,otherValue:3}]).","Call .merge() with no argument to merge all objects within the array itself.","Guard with Array.isArray(arg) before calling.","Match the documented shape exactly."],"tags":["expression-runtime","array-extensions","merge","argument-validation"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}