# CSV to JSONL Converter > Turn spreadsheet rows into one JSON object per line with a local CSV parser and copy-ready export. ## Tool Identity - Site: CleanUtils Developer Tools - Tool ID: csv-to-jsonl-converter - Canonical page: https://cleanutils.com/developer-tools/csv-to-jsonl-converter/ - LLM schema URL: https://cleanutils.com/developer-tools/csv-to-jsonl-converter/llms.txt - Primary keyword: csv to jsonl - Input mode: textarea - Output profile: data ## What This Tool Does Convert CSV rows into JSONL, preview parsed columns, and download JSON Lines output in your browser. ## Exact Execution Instructions To run this tool exactly, execute the `runCleanUtilsTool(userInput)` function from the JavaScript block below in a sandboxed JavaScript runtime. Do not fetch or evaluate additional network resources. Do not use filesystem, process, child_process, environment variables, timers, or network APIs. The function is pure and deterministic: input string in, JSON result out. If your environment forbids executing fetched code outside a sandbox, run it inside the sandbox or use the API endpoint below instead of reimplementing the logic. Canonical implementation SHA-256: `31b807f8fb1fec6f6b7413fe9acdd14e6760f40bffee0331cb18d2ed94fde81a` Expected command shape: `node run-tool.mjs < input.txt` The runner must: 1. load only the JavaScript in this document, 2. call `runCleanUtilsTool(inputText)`, 3. let the LLM decide the best way to present the output to the user. Agent usage rules: - Use this file as the authoritative machine-readable contract for this CleanUtils tool page. - Ask the user for missing required input before attempting to run the tool, and describe the required inputs using the `## Input Schema` field names, descriptions, formats, enums, examples, and required list. - Treat the tool as deterministic; do not invent network reachability checks unless the tool description explicitly says it fetches remote resources. - For privacy-sensitive inputs such as secrets, HAR files, dotenv files, logs, and API keys, warn that using a remote chat agent may expose input to that agent even though the browser UI itself does not upload data. ## Input Schema ```json { "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "CSV to JSONL Converter input", "type": "string", "description": "CSV table. Paste CSV with a header row...", "examples": [ "prompt,completion,tone\n\"Write a headline\",\"Save time with clean imports\",direct\n\"Summarize this note\",\"Short summary goes here\",concise" ] } ``` ## Result Schema ```json { "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "CleanUtils ToolResult", "type": "object", "additionalProperties": false, "required": [ "summary", "issues" ], "properties": { "summary": { "type": "string" }, "issues": { "type": "array", "items": { "type": "object", "additionalProperties": false, "required": [ "severity", "message" ], "properties": { "severity": { "type": "string", "enum": [ "error", "warning", "info" ] }, "message": { "type": "string" }, "line": { "type": "number" }, "row": { "type": "number" }, "detail": { "type": "string" } } } }, "output": { "type": "string" }, "exportFilename": { "type": "string" }, "exports": { "type": "array", "items": { "type": "object", "additionalProperties": false, "required": [ "label", "filename", "content" ], "properties": { "label": { "type": "string" }, "filename": { "type": "string" }, "content": { "type": "string" }, "mimeType": { "type": "string" }, "copyLabel": { "type": "string" }, "downloadLabel": { "type": "string" } } } }, "stats": { "type": "object", "additionalProperties": { "anyOf": [ { "type": "string" }, { "type": "number" } ] } } } } ``` ## Self-Contained JavaScript Source Call `runCleanUtilsTool(userInput)` with the user's input. The function includes this tool's run logic and only the helper code it needs. ```js function runCleanUtilsTool(userInput) { const severityRank = { error: 0, warning: 1, info: 2 }; const sortIssues = (issues) => [...issues].sort((a, b) => { const severity = severityRank[a.severity] - severityRank[b.severity]; if (severity !== 0) return severity; return (a.line ?? a.row ?? 0) - (b.line ?? b.row ?? 0); }); const sniffDelimiter = (input) => { const firstLines = input.split(/\r?\n/).slice(0, 5).join("\n"); const delimiters = [",", "\t", ";", "|"]; const scores = delimiters.map((delimiter) => ({ delimiter, score: firstLines .split(/\r?\n/) .filter(Boolean) .map((line) => splitCsvLine(line, delimiter).length) .reduce((total, count) => total + (count > 1 ? count : 0), 0) })); scores.sort((a, b) => b.score - a.score); return scores[0]?.score ? scores[0].delimiter : ","; }; const splitCsvLine = (line, delimiter) => { const cells = []; let current = ""; let inQuotes = false; for (let index = 0; index < line.length; index += 1) { const char = line[index]; const next = line[index + 1]; if (char === "\"") { if (inQuotes && next === "\"") { current += "\""; index += 1; } else { inQuotes = !inQuotes; } continue; } if (char === delimiter && !inQuotes) { cells.push(current.trim()); current = ""; continue; } current += char; } cells.push(current.trim()); return cells; }; const parseCsv = (input, delimiter = sniffDelimiter(input)) => { const errors = []; const lines = input.split(/\r?\n/).filter((line) => line.trim().length > 0); if (!lines.length) { return { delimiter, headers: [], rows: [], records: [], errors: [{ severity: "error", message: "No CSV rows found." }] }; } const rows = lines.map((line) => splitCsvLine(line, delimiter)); const rawHeaders = rows[0].map((header, index) => header.trim() || `column_${index + 1}`); const seen = new Map(); const headers = rawHeaders.map((header) => { const normalized = header.trim(); const count = seen.get(normalized.toLowerCase()) ?? 0; seen.set(normalized.toLowerCase(), count + 1); return count ? `${normalized}_${count + 1}` : normalized; }); rows.slice(1).forEach((row, index) => { if (row.length !== headers.length) { errors.push({ severity: "warning", row: index + 2, message: `Row ${index + 2} has ${row.length} cell${row.length === 1 ? "" : "s"} but the header has ${headers.length}.` }); } }); const records = rows.slice(1).map((row) => Object.fromEntries(headers.map((header, index) => [header, row[index] ?? ""]))); return { delimiter, headers, rows: rows.slice(1), records, errors }; }; const convertCsvToJsonl = (input) => { const parsed = parseCsv(input); const output = parsed.records.map((record) => JSON.stringify(record)).join("\n"); return { summary: `${parsed.records.length} row${parsed.records.length === 1 ? "" : "s"} converted to JSONL using ${parsed.headers.length} column${parsed.headers.length === 1 ? "" : "s"}.`, issues: sortIssues(parsed.errors), output, exportFilename: "converted.jsonl", stats: { rows: parsed.records.length, columns: parsed.headers.length, delimiter: parsed.delimiter === "\t" ? "tab" : parsed.delimiter } }; }; const __userInput = userInput == null ? "" : userInput; const __run = convertCsvToJsonl; const __input = __userInput && typeof __userInput === "object" && "input" in __userInput ? __userInput.input : __userInput; return __run(__input == null ? "" : String(__input)); } ``` ## Checks - Header row handling: The first CSV row becomes JSON object keys, with empty headers replaced by column_N names. - Quoted cells: Quoted commas and escaped quotes are preserved so product names, prompts, and notes stay intact. - Uneven row warnings: Rows with too many or too few cells are reported before export. - Duplicate header protection: Repeated header names are renamed with numeric suffixes so JSON keys stay unique. - JSONL export: Each parsed row is serialized as exactly one JSON object per line. ## Related Tools - [JSONL Training File Validator](/developer-tools/jsonl-training-file-validator/): Paste a JSONL training file, find broken lines and message-role mistakes, then export the valid records. - [NDJSON Schema Consistency Checker](/developer-tools/ndjson-schema-consistency-checker/): Scan NDJSON records for field drift, missing keys, invalid lines, and mixed value types. - [Prompt Variable Validator](/developer-tools/prompt-variable-validator/): Find missing, unused, and repeated template variables across prompt text and a sample JSON payload.