{"record":{"id":"1b13802e68ba71ff","repo":"n8n-io/n8n","slug":"invalid-json-failed-to-parse","errorCode":null,"errorMessage":"Invalid JSON: failed to parse","messagePattern":"Invalid JSON: failed to parse","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/@n8n/instance-ai/src/parsers/structured-file-parser.ts","lineNumber":321,"sourceCode":"\t// Check for dangerous keys in CSV/TSV headers (consistent with JSON validation)\n\tfor (const header of rawHeaders) {\n\t\tif (DANGEROUS_KEYS.has(header.trim())) {\n\t\t\tthrow new Error(`Dangerous column header \"${header.trim()}\" found in ${format} data`);\n\t\t}\n\t}\n\n\treturn { rawHeaders, allRows: dataRows };\n}\n\nfunction parseJson(content: string): {\n\trawHeaders: string[];\n\tallRows: Array<Record<string, unknown>>;\n} {\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(content);\n\t} catch {\n\t\tthrow new Error('Invalid JSON: failed to parse');\n\t}\n\n\tif (!Array.isArray(parsed)) {\n\t\tthrow new Error('Expected a JSON array of objects, got a single value or object');\n\t}\n\n\tif (parsed.length === 0) {\n\t\treturn { rawHeaders: [], allRows: [] };\n\t}\n\n\t// Collect all keys across all objects (preserving order of first appearance)\n\tconst keySet = new Set<string>();\n\tfor (const item of parsed) {\n\t\tif (typeof item !== 'object' || item === null || Array.isArray(item)) {\n\t\t\tthrow new Error('JSON array items must be flat objects (not arrays, nulls, or primitives)');\n\t\t}\n\t\tconst dangerousKey = hasDangerousKey(item as Record<string, unknown>);\n\t\tif (dangerousKey) {","sourceCodeStart":303,"sourceCodeEnd":339,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/instance-ai/src/parsers/structured-file-parser.ts#L303-L339","documentation":"Error \"Invalid JSON: failed to parse\" thrown in n8n-io/n8n.","triggerScenarios":"Thrown at packages/@n8n/instance-ai/src/parsers/structured-file-parser.ts:321 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}