FlowiseAI/Flowise · error · Error
Invalid JSON in the Custom Document Loader Input Variables:
Error message
Invalid JSON in the Custom Document Loader Input Variables: ${exception} What it means
CustomDocumentLoader tries to JSON.parse the functionInputVariables input when it is a string. If the string is not valid JSON, the SyntaxError is caught and re-thrown with this prefix. When the input is already an object it is used as-is and never hits the parser.
Source
Thrown at packages/components/nodes/documentloaders/CustomDocumentLoader/CustomDocumentLoader.ts:88
const functionInputVariablesRaw = nodeData.inputs?.functionInputVariables
const appDataSource = options.appDataSource as DataSource
const databaseEntities = options.databaseEntities as IDatabaseEntity
const variables = await getVars(appDataSource, databaseEntities, nodeData, options)
const flow = {
chatflowId: options.chatflowid,
sessionId: options.sessionId,
chatId: options.chatId,
input
}
let inputVars: ICommonObject = {}
if (functionInputVariablesRaw) {
try {
inputVars =
typeof functionInputVariablesRaw === 'object' ? functionInputVariablesRaw : JSON.parse(functionInputVariablesRaw)
} catch (exception) {
throw new Error('Invalid JSON in the Custom Document Loader Input Variables: ' + exception)
}
}
// Some values might be a stringified JSON, parse it
for (const key in inputVars) {
let value = inputVars[key]
if (typeof value === 'string') {
value = handleEscapeCharacters(value, true)
if (value.startsWith('{') && value.endsWith('}')) {
try {
value = JSON.parse(value)
} catch (e) {
// ignore
}
}
inputVars[key] = value
}
}View on GitHub (pinned to abe4a8601a)
Solutions
- Validate the string with JSON.parse in a scratch console before pasting it into the node.
- Use double quotes around all keys and string values; remove trailing commas.
- If the value is built from variables, build the object upstream and pass it as an object rather than a JSON string so the parse branch is skipped.
Example fix
// before
inputVars = typeof functionInputVariablesRaw === 'object'
? functionInputVariablesRaw
: JSON.parse(functionInputVariablesRaw)
// after - explicit, helpful error
if (typeof functionInputVariablesRaw === 'object') {
inputVars = functionInputVariablesRaw
} else {
try { inputVars = JSON.parse(functionInputVariablesRaw) }
catch (exception) {
throw new Error(`Invalid JSON in Custom Document Loader Input Variables: ${exception.message}. Input was: ${functionInputVariablesRaw}`)
}
} Defensive patterns
Strategy: validation
Validate before calling
function parseInputVars(raw: unknown): Record<string, unknown> {
if (raw == null) return {}
if (typeof raw === 'object') return raw as Record<string, unknown>
if (typeof raw === 'string') {
try { return JSON.parse(raw) }
catch (e) { throw new Error(`functionInputVariables is not valid JSON: ${(e as Error).message}. Got: ${raw}`) }
}
throw new Error(`functionInputVariables must be an object or JSON string, got ${typeof raw}`)
}
// const inputVars = parseInputVars(nodeData.inputs?.functionInputVariables) Type guard
function isJsonString(v: unknown): v is string {
if (typeof v !== 'string') return false
try { JSON.parse(v); return true } catch { return false }
} Prevention
- Validate the JSON in a scratch console before pasting.
- Use double quotes for keys and string values; drop trailing commas.
- Pass the value as an object (not a JSON string) where possible to skip the parse branch.
When it happens
Trigger: User typed input variables as a JS-like object literal with unquoted keys (e.g., {foo: 1}); trailing comma; single quotes instead of double quotes; copy-paste introduced smart quotes; templated variable produced a partial JSON fragment.
Common situations: Confusing JSON syntax with JS object literal syntax; passing a comma-separated 'key=value' list instead of JSON; a templated {{variable}} injecting unescaped quotes.
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 ChatOpenAI's BaseOptions: ${exception}
- Invalid JSON in the ChatOpenAI's BaseOptions: ${exception}
- Invalid JSON in the ChatOpenRouter's BaseOptions: ${exceptio
- Invalid JSON in Search Domain Filter: ${exception}
AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12).
Data as JSON: /api/errors/8572842c46c0a70b.
Report an issue: GitHub.