FlowiseAI/Flowise · error · Error
Invalid JSON string: ${error instanceof Error ? error.messag
Error message
Invalid JSON string: ${error instanceof Error ? error.message : 'Parse error'} What it means
Thrown by JSONPathExtractorTool._call when the json argument is a string that fails JSON.parse, with returnNullOnError disabled. The schema accepts string | object | array; objects/arrays skip parsing, but strings are assumed to be serialized JSON. The original parse error message (e.g. 'Unexpected token ... in JSON at position N') is appended so the caller can locate the malformed byte.
Source
Thrown at packages/components/nodes/tools/JSONPathExtractor/JSONPathExtractor.ts:48
// Validate that path is configured
if (!this.path) {
if (this.returnNullOnError) {
return 'null'
}
throw new Error('No extraction path configured')
}
let data: any
// Parse JSON string if needed
if (typeof json === 'string') {
try {
data = JSON.parse(json)
} catch (error) {
if (this.returnNullOnError) {
return 'null'
}
throw new Error(`Invalid JSON string: ${error instanceof Error ? error.message : 'Parse error'}`)
}
} else {
data = json
}
// Extract value using lodash get
const value = get(data, this.path)
if (value === undefined) {
if (this.returnNullOnError) {
return 'null'
}
const jsonPreview = JSON.stringify(data, null, 2)
const preview = jsonPreview.length > 200 ? jsonPreview.substring(0, 200) + '...' : jsonPreview
throw new Error(`Path "${this.path}" not found in JSON. Received: ${preview}`)
}
return typeof value === 'string' ? value : JSON.stringify(value)View on GitHub (pinned to abe4a8601a)
Solutions
- Strip code fences and surrounding prose from the input before invoking: json.replace(/```json|```/g,'').trim().
- If the source might be non-JSON, enable returnNullOnError to degrade gracefully.
- Validate upstream with a JSON.parse guard and surface the position to fix the emitter.
- If the data is already an object, pass it as an object (the schema allows it) instead of re-stringifying.
Example fix
// before
await extractor.invoke({ json: 'Here is the data: {"a":1}' })
// after
const clean = raw.replace(/^[^{[]*/, '').trim()
await extractor.invoke({ json: clean }) Defensive patterns
Strategy: type-guard
Validate before calling
function asJsonInput(json: unknown): any {
if (typeof json !== 'string') return json // already object/array
const trimmed = json.replace(/```json|```/g, '').trim()
try {
return JSON.parse(trimmed)
} catch (e) {
throw new Error(`input is not valid JSON: ${(e as Error).message}`)
}
} Type guard
function isParsableJson(s: unknown): s is string {
if (typeof s !== 'string') return false
try { JSON.parse(s.replace(/```json|```/g,'').trim()); return true } catch { return false }
} Try / catch
try {
return await extractor.invoke({ json: asJsonInput(raw) })
} catch (e) {
if (e instanceof Error && e.message.startsWith('Invalid JSON string:')) {
// strip prose/fences and retry, or enable returnNullOnError
}
throw e
} Prevention
- Strip Markdown code fences and surrounding prose from LLM output before extracting.
- Pass objects directly (the schema allows it) instead of re-stringifying.
- Enable returnNullOnError when the input source is untrusted.
- Validate upstream with JSON.parse to catch the position of the malformed byte.
When it happens
Trigger: An upstream node emits prettified JSON with trailing comments, a JS object literal (unquoted keys), a Markdown-fenced ```json block, or text that merely resembles JSON. Also when a stringified value is double-decoded or when the LLM wraps the JSON in prose.
Common situations: LLM output piped directly into the extractor without stripping reasoning text; CSV/YAML fed where JSON was expected; copy-paste introducing smart quotes; a previous extractor step that already returned an object but the wiring typed it as string.
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
- Values must be a valid JSON array
- chatflowId must be a valid array
- Invalid JSON in executeFlowOverrideConfig: ${parseError.mess
- Invalid input array
- Invalid Flow State
AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12).
Data as JSON: /api/errors/73fed522645b5691.
Report an issue: GitHub.