n8n-io/n8n · error · Error

replacements must be an array of {old_str, new_str} objects.

Error message

replacements must be an array of {old_str, new_str} objects. Example: {"replacements": [{"old_str": "foo", "new_str": "bar"}]}

What it means

Error "replacements must be an array of {old_str, new_str} objects. Example: {"replacements": [{"old_str": "foo", "new_str": "bar"}]}" thrown in n8n-io/n8n.

Source

Thrown at packages/@n8n/ai-utilities/src/utils/text-editor.ts:185

		`  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}.`,
			);
		}
		if (typeof item.new_str !== 'string') {
			throw new Error(
				`replacements[${i}] is missing a valid "new_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:185 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12). Data as JSON: /api/errors/0ce48d96fbe224e6. Report an issue: GitHub.