n8n-io/n8n · error · Error
replacements must be a JSON array of {old_str, new_str} obje
Error message
replacements must be a JSON array of {old_str, new_str} objects, but received an invalid JSON string. What it means
Error "replacements must be a JSON array of {old_str, new_str} objects, but received an invalid JSON string." thrown in n8n-io/n8n.
Source
Thrown at packages/@n8n/ai-utilities/src/utils/text-editor.ts:178
.slice(startLine, endLine)
.map((line, i) => ` ${startLine + i + 1}: ${line}`)
.join('\n');
return (
`Closest match (${percentage}% of old_str matched, diverges at line ${divergeLine}):\n` +
` old_str: ...${escapeWhitespace(oldStrPrefix)}>>> ${escapeWhitespace(oldStrRemainder)}\n` +
` file:\n${fileContext}`
);
}
export function parseStrReplacements(raw: unknown): StrReplacement[] {
let parsed = raw;
if (typeof parsed === 'string') {
try {
parsed = JSON.parse(parsed) as unknown;
} catch {
throw new Error(
'replacements must be a JSON array of {old_str, new_str} objects, but received an invalid JSON string.',
);
}
}
if (!isUnknownArray(parsed)) {
throw new Error(
'replacements must be an array of {old_str, new_str} objects. Example: {"replacements": [{"old_str": "foo", "new_str": "bar"}]}',
);
}
const replacements: StrReplacement[] = [];
for (let i = 0; i < parsed.length; i++) {
const item = parsed[i];
if (!isObjectRecord(item) || typeof item.old_str !== 'string') {
throw new Error(
`replacements[${i}] is missing a valid "old_str" string. Each replacement must have {old_str: string, new_str: string}.`,View on GitHub (pinned to 5ac6606e81)
When it happens
Trigger: Thrown at packages/@n8n/ai-utilities/src/utils/text-editor.ts:178 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/877c74cfadf1da34.
Report an issue: GitHub.