{"record":{"id":"58b61f8abf7eecc9","repo":"gchq/CyberChef","slug":"unable-to-parse-csv-err","errorCode":null,"errorMessage":"Unable to parse CSV: ${err}","messagePattern":"Unable to parse CSV: (.+?)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/CSVToJSON.mjs","lineNumber":59,"sourceCode":"                type: \"option\",\n                value: [\"Array of dictionaries\", \"Array of arrays\"]\n            }\n        ];\n    }\n\n    /**\n     * @param {string} input\n     * @param {Object[]} args\n     * @returns {JSON}\n     */\n    run(input, args) {\n        const [cellDelims, rowDelims, format] = args;\n        let json, header;\n\n        try {\n            json = Utils.parseCSV(input, cellDelims.split(\"\"), rowDelims.split(\"\"));\n        } catch (err) {\n            throw new OperationError(\"Unable to parse CSV: \" + err);\n        }\n\n        switch (format) {\n            case \"Array of dictionaries\":\n                header = json[0];\n                return json.slice(1).map(row => {\n                    const obj = {};\n                    header.forEach((h, i) => {\n                        obj[h] = row[i];\n                    });\n                    return obj;\n                });\n            case \"Array of arrays\":\n            default:\n                return json;\n        }\n    }\n","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/CSVToJSON.mjs#L41-L77","documentation":"Thrown when Utils.parseCSV cannot tokenize the input as CSV using the supplied cell and row delimiters. The inner error from the parser is appended, so the message carries the concrete parse failure. It indicates the delimiter configuration does not match the input's actual structure.","triggerScenarios":"CSVToJSON.run is called where cellDelims or rowDelims strings (split into char arrays) do not correspond to characters present in input, or the input has mixed/escaped quoting the parser cannot reconcile. Passing an empty delimiter string or delimiters that collide with quoted field content also triggers it.","commonSituations":"Input uses CRLF rows but only LF is configured as row delimiter; tab-separated data parsed with comma cell delimiter; delimiter strings entered as multi-character (the code splits them into single chars) causing partial matches; input containing stray quote characters.","solutions":["Read err in the message — it names the specific tokenizer failure.","Verify cellDelims/rowDelims: each is split('') so pass a single-character string (e.g. ',' and '\\n' or '\\r\\n' won't work as one unit; use the actual separator chars).","Normalize input line endings before the operation if rows are CRLF.","Quote/escape fields per RFC 4180, or strip stray quotes from input."],"exampleFix":"// before\nUtils.parseCSV(input, [\";\"].join(\"\").split(\"\"), [\"\\r\\n\"].join(\"\").split(\"\"));\n// after — use real separator characters, one char each\nUtils.parseCSV(input, [\";\"], [\"\\n\"]);","handlingStrategy":"validation","validationCode":"function csvLooksValid(input, cellDelims, rowDelims) {\n  if (!input || !input.length) return false;\n  if (!cellDelims || !cellDelims.length || !rowDelims || !rowDelims.length) return false;\n  // delimiters are split into single chars — ensure at least one row delim actually appears\n  const rowChars = rowDelims.split(\"\");\n  return rowChars.some(c => input.indexOf(c) !== -1);\n}","typeGuard":"null","tryCatchPattern":"try {\n  json = Utils.parseCSV(input, cellDelims.split(\"\"), rowDelims.split(\"\"));\n} catch (err) {\n  throw new OperationError(\"Unable to parse CSV: \" + err);\n}","preventionTips":["Pass single-character delimiter strings; the API splits them into char arrays.","Ensure the row delimiter actually occurs in the input.","Normalize line endings (CRLF → LF) before parsing.","Inspect the appended err to find the tokenizer's specific complaint."],"tags":["csv","json","parsing","delimiters"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}