{"record":{"id":"d55480c2e6ec9bf2","repo":"FlowiseAI/Flowise","slug":"invalid-json-in-the-custom-function-input-variable-d55480","errorCode":null,"errorMessage":"Invalid JSON in the Custom Function Input Variables: ${exception}","messagePattern":"Invalid JSON in the Custom Function Input Variables: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/utilities/CustomFunction/CustomFunction.ts","lineNumber":105,"sourceCode":"            input,\n            chatflowId: options.chatflowid,\n            sessionId: options.sessionId,\n            chatId: options.chatId,\n            rawOutput: options.postProcessing?.rawOutput || '',\n            chatHistory: options.postProcessing?.chatHistory || [],\n            sourceDocuments: options.postProcessing?.sourceDocuments,\n            usedTools: options.postProcessing?.usedTools,\n            artifacts: options.postProcessing?.artifacts,\n            fileAnnotations: options.postProcessing?.fileAnnotations\n        }\n\n        let inputVars: ICommonObject = {}\n        if (functionInputVariablesRaw) {\n            try {\n                inputVars =\n                    typeof functionInputVariablesRaw === 'object' ? functionInputVariablesRaw : JSON.parse(functionInputVariablesRaw)\n            } catch (exception) {\n                throw new Error('Invalid JSON in the Custom Function Input Variables: ' + exception)\n            }\n        }\n\n        // Some values might be a stringified JSON, parse it\n        for (const key in inputVars) {\n            let value = inputVars[key]\n            if (typeof value === 'string') {\n                value = handleEscapeCharacters(value, true)\n                if (value.startsWith('{') && value.endsWith('}')) {\n                    try {\n                        value = JSON.parse(value)\n                    } catch (e) {\n                        // ignore\n                    }\n                }\n                inputVars[key] = value\n            }\n        }","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/utilities/CustomFunction/CustomFunction.ts#L87-L123","documentation":"Thrown by CustomFunction_Utilities.init when JSON.parse fails on `functionInputVariablesRaw`. The field is parsed only when it is a non-object (a JSON string); objects are passed through. Any invalid JSON string aborts custom-function execution before the sandbox is built.","triggerScenarios":"A user enters malformed JSON in the Custom Function node's Input Variables editor (trailing comma, unquoted keys, single quotes, stray characters); a flow variable returns a partial/cut-off JSON string; copy-paste introduced smart quotes.","commonSituations":"Hand-typed JSON in the node config with a syntax error; JSON truncated by a length limit upstream; mixed quote styles from a word processor; a variable resolved to a non-JSON string at runtime.","solutions":["Validate the JSON in an external linter before pasting into the node.","Use the Flowise JSON editor's validation (if available) or a JSON editor extension.","If the value is already an object at runtime, pass it as an object — the code skips JSON.parse for objects.","Trim/escape the string and retry."],"exampleFix":"// before (malformed)\nfunctionInputVariablesRaw = \"{ key: 'value', }\" // throws: Invalid JSON ...\n\n// after (valid)\nfunctionInputVariablesRaw = '{\"key\":\"value\"}'","handlingStrategy":"validation","validationCode":"function parseInputVars(raw: unknown): Record<string, unknown> {\n  if (raw == null) return {}\n  if (typeof raw === 'object') return raw as Record<string, unknown>\n  try { return JSON.parse(raw as string) }\n  catch (e) { throw new Error(`functionInputVariables is not valid JSON: ${(e as Error).message}`) }\n}\n// validate before the node runs\nconst inputVars = parseInputVars(functionInputVariablesRaw)","typeGuard":"const isParsableJsonObject = (v: unknown): boolean => {\n  if (typeof v === 'object' && v !== null) return true\n  if (typeof v !== 'string') return false\n  try { return typeof JSON.parse(v) === 'object' && JSON.parse(v) !== null } catch { return false }\n}","tryCatchPattern":"try { JSON.parse(functionInputVariablesRaw as string) }\ncatch (e) { throw new Error(`Fix the Custom Function Input Variables JSON: ${(e as Error).message}`) }","preventionTips":["Use a JSON editor with syntax validation for node config.","If the value is already an object, pass it as an object to skip parsing.","Lint input-variable JSON in CI for flows stored as code.","Avoid copy-pasting from rich-text editors that introduce smart quotes."],"tags":["json","parsing","configuration","custom-function"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}