{"record":{"id":"877c74cfadf1da34","repo":"n8n-io/n8n","slug":"replacements-must-be-a-json-array-of-old-str-new","errorCode":null,"errorMessage":"replacements must be a JSON array of {old_str, new_str} objects, but received an invalid JSON string.","messagePattern":"replacements must be a JSON array of (.+?) objects, but received an invalid JSON string\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/ai-utilities/src/utils/text-editor.ts","lineNumber":178,"sourceCode":"\t\t.slice(startLine, endLine)\n\t\t.map((line, i) => `    ${startLine + i + 1}: ${line}`)\n\t\t.join('\\n');\n\n\treturn (\n\t\t`Closest match (${percentage}% of old_str matched, diverges at line ${divergeLine}):\\n` +\n\t\t`  old_str: ...${escapeWhitespace(oldStrPrefix)}>>> ${escapeWhitespace(oldStrRemainder)}\\n` +\n\t\t`  file:\\n${fileContext}`\n\t);\n}\n\nexport function parseStrReplacements(raw: unknown): StrReplacement[] {\n\tlet parsed = raw;\n\n\tif (typeof parsed === 'string') {\n\t\ttry {\n\t\t\tparsed = JSON.parse(parsed) as unknown;\n\t\t} catch {\n\t\t\tthrow new Error(\n\t\t\t\t'replacements must be a JSON array of {old_str, new_str} objects, but received an invalid JSON string.',\n\t\t\t);\n\t\t}\n\t}\n\n\tif (!isUnknownArray(parsed)) {\n\t\tthrow new Error(\n\t\t\t'replacements must be an array of {old_str, new_str} objects. Example: {\"replacements\": [{\"old_str\": \"foo\", \"new_str\": \"bar\"}]}',\n\t\t);\n\t}\n\n\tconst replacements: StrReplacement[] = [];\n\n\tfor (let i = 0; i < parsed.length; i++) {\n\t\tconst item = parsed[i];\n\t\tif (!isObjectRecord(item) || typeof item.old_str !== 'string') {\n\t\t\tthrow new Error(\n\t\t\t\t`replacements[${i}] is missing a valid \"old_str\" string. Each replacement must have {old_str: string, new_str: string}.`,","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/ai-utilities/src/utils/text-editor.ts#L160-L196","documentation":"Error \"replacements must be a JSON array of {old_str, new_str} objects, but received an invalid JSON string.\" thrown in n8n-io/n8n.","triggerScenarios":"Thrown at packages/@n8n/ai-utilities/src/utils/text-editor.ts:178 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}