Fixes problematic json parsing in Iteration.ts (#5077)
Resolves the json parsing issue in Iteration.ts gracefully
This commit is contained in:
parent
55f8f69060
commit
44087bc706
|
|
@ -39,12 +39,17 @@ class Iteration_Agentflow implements INode {
|
||||||
const iterationInput = nodeData.inputs?.iterationInput
|
const iterationInput = nodeData.inputs?.iterationInput
|
||||||
|
|
||||||
// Helper function to clean JSON strings with redundant backslashes
|
// Helper function to clean JSON strings with redundant backslashes
|
||||||
const cleanJsonString = (str: string): string => {
|
const safeParseJson = (str: string): string => {
|
||||||
return str.replace(/\\(["'[\]{}])/g, '$1')
|
try {
|
||||||
|
return JSON.parse(str)
|
||||||
|
} catch {
|
||||||
|
// Try parsing after cleaning
|
||||||
|
return JSON.parse(str.replace(/\\(["'[\]{}])/g, '$1'))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const iterationInputArray =
|
const iterationInputArray =
|
||||||
typeof iterationInput === 'string' && iterationInput !== '' ? JSON.parse(cleanJsonString(iterationInput)) : iterationInput
|
typeof iterationInput === 'string' && iterationInput !== '' ? safeParseJson(iterationInput) : iterationInput
|
||||||
|
|
||||||
if (!iterationInputArray || !Array.isArray(iterationInputArray)) {
|
if (!iterationInputArray || !Array.isArray(iterationInputArray)) {
|
||||||
throw new Error('Invalid input array')
|
throw new Error('Invalid input array')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue