{"record":{"id":"962bc15aa876e9ff","repo":"FlowiseAI/Flowise","slug":"invalid-json-in-structuredoutputparser-exceptio","errorCode":null,"errorMessage":"Invalid JSON in StructuredOutputParser: ${exception}","messagePattern":"Invalid JSON in StructuredOutputParser: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/outputparsers/StructuredOutputParser/StructuredOutputParser.ts","lineNumber":95,"sourceCode":"\n            const baseParse = structuredOutputParser.parse\n\n            // Fix broken JSON from LLM\n            structuredOutputParser.parse = (text) => {\n                const jsonString = text.includes('```') ? text.trim().split(/```(?:json)?/)[1] : text.trim()\n                return baseParse.call(structuredOutputParser, jsonrepair(jsonString))\n            }\n\n            // NOTE: When we change Flowise to return a json response, the following has to be changed to: JsonStructuredOutputParser\n            Object.defineProperty(structuredOutputParser, 'autoFix', {\n                enumerable: true,\n                configurable: true,\n                writable: true,\n                value: autoFix\n            })\n            return structuredOutputParser\n        } catch (exception) {\n            throw new Error('Invalid JSON in StructuredOutputParser: ' + exception)\n        }\n    }\n}\n\nmodule.exports = { nodeClass: StructuredOutputParser }\n","sourceCodeStart":77,"sourceCodeEnd":101,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/outputparsers/StructuredOutputParser/StructuredOutputParser.ts#L77-L101","documentation":"StructuredOutputParser.init wraps its parser construction in try/catch and rethrows any failure as 'Invalid JSON in StructuredOutputParser'. The catch is broad — it captures failures from JSON.parse on the schema string, jsonrepair attempts, and defineProperty operations on the structured output parser instance.","triggerScenarios":"The schema JSON input is malformed (unbalanced braces, single quotes, trailing commas); the jsonrepair library cannot recover the string; defineProperty fails on a frozen/sealed parser instance.","commonSituations":"Hand-editing the JSON schema field; passing a schema string that includes comments or JS object syntax; version mismatch where the structured output parser shape changed.","solutions":["Validate the schema JSON with a JSON linter before pasting.","Inspect `exception.message` for the parse offset and fix the cited location.","If jsonrepair is failing, simplify the schema to find the unparseable fragment.","Ensure the schema string is a plain JSON object, not a JS object literal."],"exampleFix":"// before\n} catch (exception) {\n  throw new Error('Invalid JSON in StructuredOutputParser: ' + exception)\n}\n// after\n} catch (exception) {\n  const msg = exception instanceof Error ? exception.message : String(exception)\n  throw new Error(`Invalid JSON in StructuredOutputParser: ${msg}. Input was: ${jsonString?.slice(0, 200)}`)\n}","handlingStrategy":"validation","validationCode":"function safeParseSchema(s: string): unknown {\n  try { return JSON.parse(s) }\n  catch {\n    try { return JSON.parse(jsonrepair(s)) }\n    catch (e) { throw new Error(`Schema JSON unparseable: ${(e as Error).message}`) }\n  }\n}","typeGuard":"const isJsonString = (s: string): boolean => { try { JSON.parse(s); return true } catch { return false } }","tryCatchPattern":"try { /* build parser */ }\ncatch (e) { throw new Error(`StructuredOutputParser failed: ${(e as Error).message}. Input: ${jsonString.slice(0,200)}`) }","preventionTips":["Lint schema JSON externally before pasting.","Avoid JS object literals and comments.","Inspect parse error offsets to locate the bad fragment."],"tags":["json","output-parser","validation","schema"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}