FlowiseAI/Flowise · error · Error

Invalid JSON in the IfElse's Input Variables: ${exception}

Error message

Invalid JSON in the IfElse's Input Variables: ${exception}

What it means

Thrown by IfElseFunction_Utilities.init when JSON.parse fails on `functionInputVariablesRaw`. Structurally identical to error 492 in CustomFunction: a non-object value is treated as a JSON string and parsed; failure aborts before the if/else sandbox runs.

Source

Thrown at packages/components/nodes/utilities/IfElseFunction/IfElseFunction.ts:101

        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 IfElse's 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

  1. Validate the JSON in an external linter before saving the node.
  2. If the value is an object at runtime, pass it as an object to skip parsing.
  3. Trim whitespace/escape characters and retry.
  4. Use a JSON editor with syntax checking.

Example fix

// before (malformed)
functionInputVariablesRaw = "{ a: 1, }" // throws: Invalid JSON in the IfElse's Input Variables

// after (valid)
functionInputVariablesRaw = '{"a":1}'
Defensive patterns

Strategy: validation

Validate before calling

function parseIfElseInputVars(raw: unknown): Record<string, unknown> {
  if (raw == null) return {}
  if (typeof raw === 'object') return raw as Record<string, unknown>
  try { return JSON.parse(raw as string) }
  catch (e) { throw new Error(`IfElse Input Variables is not valid JSON: ${(e as Error).message}`) }
}

Type guard

const isParsableJson = (v: unknown): boolean => {
  if (typeof v === 'object' && v !== null) return true
  if (typeof v !== 'string') return false
  try { JSON.parse(v); return true } catch { return false }
}

Try / catch

try { JSON.parse(functionInputVariablesRaw as string) }
catch (e) { throw new Error(`Fix the IfElse Input Variables JSON: ${(e as Error).message}`) }

Prevention

When it happens

Trigger: Malformed JSON in the IfElse node's Input Variables field; a flow variable returns a non-JSON string; trailing comma, unquoted keys, smart quotes, truncation.

Common situations: Hand-typed JSON with a syntax error; copy-paste from a rich-text editor; variable resolved to a partial string; mixed quote styles.

Understand the failure class

Related errors


AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12). Data as JSON: /api/errors/1d0eefb85ae54159. Report an issue: GitHub.