FlowiseAI/Flowise · error · Error
Invalid JSON format in body. Original error: ${error.message
Error message
Invalid JSON format in body. Original error: ${error.message}. After cleanup attempts: ${secondError.message}. 3rd attempt: ${thirdError.message}. Final attempt: ${fourthError.message}.\n\nCommon fixes:\n${suggestions.join('\n')}\n\nReceived body: ${body.substring(0, 200)}${body.length > 200 ? '...' : ''} What it means
Thrown after JSON/JSON5 parsing fails four successive attempts (JSON5 original, JSON5 cleaned, JSON.parse original, JSON.parse cleaned). The message aggregates all four error messages plus remediation hints and a 200-char preview of the received body. It indicates the input is structurally not parseable JSON even after common cleanup (trailing commas, single quotes, comments, backslash escapes).
Source
Thrown at packages/components/src/utils.ts:1947
const finalCleanedBody = body
// eslint-disable-next-line
.replace(/\\(?=[\[\]{}])/g, '') // Basic escape cleanup
.replace(/,(\s*[}\]])/g, '$1') // Remove trailing commas
.trim()
return JSON.parse(finalCleanedBody)
} catch (fourthError) {
// Provide comprehensive error message with suggestions
const suggestions = [
'• Ensure all strings are enclosed in double quotes',
'• Remove trailing commas',
'• Remove comments (// or /* */)',
'• Escape special characters properly (\\n for newlines, \\" for quotes)',
'• Use double quotes instead of single quotes',
'• Remove unnecessary backslashes before brackets [ ] { }'
]
throw new Error(
`Invalid JSON format in body. Original error: ${error.message}. ` +
`After cleanup attempts: ${secondError.message}. 3rd attempt: ${thirdError.message}. Final attempt: ${fourthError.message}.\n\n` +
`Common fixes:\n${suggestions.join('\n')}\n\n` +
`Received body: ${body.substring(0, 200)}${body.length > 200 ? '...' : ''}`
)
}
}
}
}
}
/**
* Parse a value against a Zod schema with automatic type conversion for common type mismatches
* @param schema - The Zod schema to parse against
* @param arg - The value to parse
* @param maxDepth - Maximum recursion depth to prevent infinite loops (default: 10)
* @returns The parsed value
* @throws Error if parsing fails after attempting type conversionsView on GitHub (pinned to abe4a8601a)
Solutions
- Inspect the 200-char preview in the message to see what was actually received (HTML? truncated? wrong format?).
- Fix the upstream sender to send well-formed JSON with double quotes, no trailing commas, no comments.
- If a proxy injects error pages, ensure requests reach the API route (check Content-Type and routing).
- Increase any body-size limits so payloads aren't truncated before parsing.
Example fix
// before — single throw with aggregated message
throw new Error(`Invalid JSON format in body. Original error: ${error.message}. ... Received body: ${body.substring(0,200)}...`)
// caller-side: guard before calling the parser
if (!body || !body.trim().startsWith('{') && !body.trim().startsWith('[')) {
return res.status(400).json({ error: 'Expected JSON object or array', preview: body.substring(0, 200) })
} Defensive patterns
Strategy: validation
Validate before calling
function looksLikeJson(body: string): boolean {
const t = (body || '').trim()
return t.startsWith('{') || t.startsWith('[')
} Type guard
function isJsonArrayOrObject(body: string): boolean {
const t = body.trim()
if (!t.startsWith('{') && !t.startsWith('[')) return false
try { JSON.parse(t); return true } catch { return false }
} Try / catch
if (!looksLikeJson(body)) {
throw new Error(`Expected JSON object or array. Received (${body.length} chars): ${body.substring(0, 200)}`)
} Prevention
- Reject non-JSON bodies at the route boundary (400) before parsing.
- Ensure reverse proxies return JSON error bodies, not HTML, on application/json routes.
- Cap request body size to avoid truncated-payload parsing failures.
When it happens
Trigger: Body is HTML (e.g. an error page from a proxy) instead of JSON; body is truncated by a proxy/gateway mid-payload; body uses a non-JSON format (YAML, XML, form-encoded); nested string contains an unescaped control character; surrogate pairs broken by truncation.
Common situations: Reverse proxy returning its own HTML error page with Content-Type application/json; client sending multipart/form-data but the handler expects JSON; load balancer truncating oversized bodies; AI-generated payloads with subtle syntax errors that the cleanup heuristics can't fix.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Invalid JSON in the Chat NVIDIA NIM's baseOptions: ${excepti
- Invalid JSON in the OpenAIEmbedding's BaseOptions:
- Invalid JSON in the ChatOpenAI's BaseOptions:
- Invalid JSON in the OpenAI's BaseOptions:
- Invalid JSON in the Additional Configuration:
AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12).
Data as JSON: /api/errors/70c23073f3d15e42.
Report an issue: GitHub.