Solved.tools โ€” Free Online Calculators & Tools

We use cookies for analytics and advertising. Learn more about our cookie policy

CSV to JSON Converter

Last updated: 16 August 2026

Reviewed by Gavin ยท Research and drafting assisted by AI

CSV to JSON Converter

Convert RFC 4180 comma-separated text into a JSON array of objects. Everything runs in your browser โ€” no upload.

Rows: 3 ยท Columns: 3
Was this helpful?


CSV to JSON Converter

The CSV to JSON converter translates comma-separated text into a JSON array of objects, one object per data row, with column headers carrying through as keys. The tool follows RFC 4180 (Common Format and MIME Type for Comma-Separated Values Files) for the parser and emits output that conforms to RFC 8259 / ECMA-404 / IETF STD 90 (the JSON data interchange format). Everything runs in your browser: nothing is uploaded, nothing is logged, and the parser is a strict character-by-character state machine that handles quoted fields, embedded commas, escaped quotes, multi-line cells, and CR / LF / CRLF line endings without losing data.

CSV is the lingua franca for tabular data exchange. Every spreadsheet program can export it, every database can dump it, every analytics tool can ingest it. JSON is the lingua franca for structured data on the web. Almost every modern API, every NoSQL database, and every JavaScript runtime consumes JSON natively. The gap between them is the most common "tiny but tedious" task in data engineering, and the gap is exactly what this converter closes. Paste any CSV, see the JSON in one keystroke, copy or download it.

How to Use

  1. Paste or type CSV into the CSV input area on the left. The example file is loaded automatically so you can see the converter working immediately.
  2. Toggle the header row option (default ON). When ON, the first row becomes the keys of the resulting objects; when OFF, the keys are auto-generated as col_1, col_2, col_3, and so on.
  3. Toggle numeric autodetect (default ON). With this on, CSV cells that look like numbers (30, 3.14, -1.5e10) are emitted as JSON numbers instead of strings. Cells with leading zeros (zip codes, SKUs, phone numbers) are deliberately preserved as strings.
  4. Toggle pretty output (default ON). ON emits 2-space indented JSON for human readability; OFF emits minified JSON for compactness in production payloads.
  5. Read the JSON in the output area on the right. It updates live as you type or toggle options.
  6. Copy JSON with the copy button. The button briefly shows "โœ“ Copied!" once the clipboard write succeeds.
  7. Download JSON to save the result as data.json. The download is a standard <a download> click, no round-trip to a server.
  8. Clear the input area at any time, or Load example to restore the 3-row sample.

The Parser Algorithm

The parser is a single-pass character state machine. It walks the input one character at a time and tracks exactly two bits of state: whether the current field is inside quotes (inQuotes) and what is currently being assembled (the open field buffer and the open row buffer). Two constants, the delimiter (default ,) and the line terminator (any of \r, \n, or \r\n), drive the state transitions.

The state machine has two top-level modes:

  • Out-of-quote state. Each character is interpreted as control or content. A " toggles the parser into in-quote state and marks the start of a quoted field. A , flushes the current field into the current row and starts a new field. A \r or \n flushes the current field, then the current row, into the output and starts a new row. Any other character is appended to the current field.
  • In-quote state. Everything inside the quotes is treated as literal content except the quote rules. A " followed by another " is an escaped quote, decoded to a single literal " and added to the field. A " followed by anything else closes the quoted field and returns to out-of-quote state. CR and LF inside quotes are preserved verbatim, which means a single CSV record can span multiple physical lines.

The trailing flush at the end of the file pushes whatever is left in the row buffer (if anything) as a final row. If the parser is in in-quote state at the end of input, it reports an unterminated-quote error instead of silently dropping data.

Once the rows are extracted, the converter applies two more steps:

  1. Header promotion. If the header toggle is ON, the first row is consumed as object keys, and the remaining rows become the object array. Duplicate or empty header cells are de-duplicated to name, name_2, name_3, and so on, so the output is always valid JSON.
  2. Numeric and boolean coercion. If the numeric-autodetect toggle is ON, every cell is run through a strict numeric regex that requires the full string to be a valid number, so "30" becomes 30, but "30abc" stays "30abc". Leading zeros are preserved ("01234" stays a string so zip codes survive). The literals true, false, and null are also coerced when lowercase or uppercase.

The output is then run through JSON.stringify with either 2-space indent or compact whitespace, depending on the pretty toggle. The result is a JSON array of objects that any JSON parser in any language can read.

Worked Examples

Example 1, Header row with numeric autodetect. The CSV name,age followed by Alice,30 and Bob,25 is parsed as three rows: ["name","age"], ["Alice","30"], ["Bob","25"]. The header row provides the keys, and the two data rows become objects. Numeric autodetect converts the string "30" to the number 30, so the output is [{"name":"Alice","age":30},{"name":"Bob","age":25}]. Without autodetect, age would be the string "30".

Example 2, Quoted field containing a comma. The CSV city,note followed by Paris,"Bonjour, รงa va?" is the canonical case that breaks a naive split(','). The parser enters in-quote state on the opening ", treats the comma inside the quotes as literal content, and closes the field on the matching ". The output is [{"city":"Paris","note":"Bonjour, รงa va?"}]. Without RFC 4180 quoting, the comma would split the field into two and corrupt the data.

Example 3, Escaped double quotes inside a quoted field. The CSV v followed by "He said ""hi""" is a quoted field whose content contains an escaped double quote. The parser sees the opening ", then He said as literal text, then "" which is decoded to a single ", then hi, then "" decoded to ", then the closing ". The output is [{"v":"He said \"hi\""}]. A naive parser that treats every quote as a field terminator would split this into multiple fields.

Example 4, No header row. The CSV 1,2,3 followed by 4,5,6 becomes two rows of three numeric values. With the header toggle OFF, the converter auto-generates the keys col_1, col_2, col_3. With numeric autodetect ON, the strings become numbers, so the output is [{"col_1":1,"col_2":2,"col_3":3},{"col_1":4,"col_2":5,"col_3":6}]. This is the safest format for downstream processing when the column names are unknown or unstable.

Example 5, Empty values. The CSV name,score followed by , (a row of two empty fields) and Alice, (a row with an empty score) is the stubborn case that catches many homegrown parsers. The parser correctly produces two empty strings for the first row and one string plus one empty string for the second. The output is [{"name":"","score":""},{"name":"Alice","score":""}]. JSON has no concept of "missing", so empty cells are honest signals of empty data.

Where It Shows Up

  • Data munging. The single most common task when a colleague sends a spreadsheet export and you need to load it into a script. The converter replaces writing a one-off parser for every new file.
  • ETL exploration. When exploring a new data source, a vendor's CSV dump, a government open-data release, a research dataset, the first step is usually to convert a few thousand rows to JSON so a script can iterate over them. Doing this in the browser keeps the data on your machine.
  • API testing. Many APIs accept JSON but not CSV. When you need to send a payload from a CSV fixture, converting to JSON inline is the fastest path. Many REST and GraphQL test suites expose CSV fixtures and convert to JSON as part of the test harness.
  • Log analysis. Logs are sometimes exported as CSV (one row per event, columns for timestamp, level, message). Converting to JSON lets you pipe them into tools like jq, Elasticsearch, or any JSON-aware log shipper.
  • Spreadsheet exports. Every spreadsheet, Excel, Google Sheets, Numbers, LibreOffice Calc, can export CSV. The converter is the bridge between the spreadsheet world and the JSON world.
  • Spreadsheet imports the other way. Some JSON-producing tools need a CSV mirror for downstream legacy systems. The same conversion logic in reverse is the input to that mirror.
  • Quick teaching and demos. When introducing students to JSON, comparing CSV to JSON on the same dataset is the most direct way to show the difference. The converter produces side-by-side output instantly.

Common Mistakes

  • CRLF vs LF line endings. CSV files saved on Windows usually end rows with \r\n; Unix files use \n; classic Mac files used \r alone. The parser treats all three as row terminators, but a naive split('\n') will leave a stray \r on every Windows-produced row. Always strip the trailing \r or use a parser that handles all three.
  • BOM at the start. Excel often writes a UTF-8 byte-order mark (the three bytes EF BB BF) at the start of a CSV file. If you read the file as text and the BOM is not stripped, the first header column will silently have a leading invisible character and downstream JSON keys will be wrong. Strip the BOM or read the file as UTF-8 with BOM detection.
  • Embedded quotes without escaping. A common error is writing "He said "hi"" and expecting the parser to figure it out. The RFC 4180 escape is "" (two doubled quotes), not a backslash. The parser converts "" to a single "; a stray unescaped " closes the field early.
  • Trailing comma. A row that ends with a comma, like Alice,30,, parses as three fields, the last of which is the empty string. Some tools silently drop the trailing empty field, which then shifts every column in the row. The converter preserves all fields, so a trailing comma gives you an extra empty trailing column.
  • Looking at split(',') rather than a parser. Almost every "CSV to JSON" bug report traces back to split(','). The CSV format is not a flat delimiter-separated list, it is a recursive structure where a delimiter inside a quoted field is data, not a separator. The only safe approach is a character-state parser like the one in this tool.
  • Confusing JSON output with JSON Lines. This converter emits a JSON array of objects (one root, many objects). JSON Lines (.jsonl / .ndjson) is one object per line, no enclosing array. If you need JSON Lines, post-process the output by splitting on the array commas and emitting one object per line.

Frequently Asked Questions

What is CSV?

CSV stands for comma-separated values. It is a plain-text tabular format defined by RFC 4180: each line is one record, fields are separated by commas, and a field that contains a comma, a quote, or a newline can be wrapped in double quotes. Inside a quoted field, a literal double quote is escaped by doubling it (""). The format is the lingua franca for tabular data exchange because every spreadsheet, every database, and almost every analytics tool can read or write it.

What is JSON?

JSON (JavaScript Object Notation) is a lightweight data-interchange format defined by RFC 8259 and ECMA-404 and standardised as IETF STD 90. It is built on two structures: an ordered list of values (an array) and an unordered collection of name-value pairs (an object). JSON is the lingua franca of web APIs because it is human-readable, trivially parseable in every modern language, and has a stable, versioned specification.

Why convert CSV to JSON?

The most common reason is that the next tool in your pipeline only accepts JSON. A second reason is that JSON objects give you named access instead of positional access, row['age'] is more readable than row[1]. A third reason is that JSON plays well with jq, JavaScript, NoSQL databases, and config files. CSV is for shipping and storage; JSON is for processing and querying.

Does the converter send my data anywhere?

No. Every step of the parse, conversion, and download runs in your browser using JavaScript. There is no network request, no API call, no telemetry, and no logging. You can verify this by opening the browser's network panel and watching for zero requests after the page loads.

What line endings does the parser accept?

The parser accepts any of \r, \n, and \r\n as a row terminator. This matches RFC 4180 and is the only sensible choice because CSV files are routinely exchanged between Windows (CRLF), Unix (LF), and legacy Mac (CR) systems. The parser also handles a single CSV record that spans multiple physical lines inside a quoted field.

What if my CSV has a tab or semicolon delimiter instead of a comma?

The current parser is hard-coded to comma (the RFC 4180 default). Excel in some locales saves with ; or \t, when that happens, the safest fix is to save the file again as comma-delimited, or run a one-off tr '\t' ',' in your shell. A future version of this tool may add a delimiter toggle.

Does the converter handle empty cells?

Yes. An empty cell becomes the empty string "" in the JSON output. If numeric autodetect is on, the empty string is NOT coerced to 0, it stays as "". This is intentional: empty and zero are different concepts in JSON, and conflating them silently is a common source of bugs.

What happens to numeric values when autodetect is off?

Every cell stays as a JSON string. This is the safe default if you are dealing with ID strings, zip codes, phone numbers, or anything where a leading zero is significant. The downside is that downstream code must parse the string to a number explicitly.

What is the difference between JSON and JSON Lines?

JSON is a single document format, one root, many objects, wrapped in a [ ... ] array. JSON Lines (.jsonl / .ndjson) is a streaming format, one object per line, no commas between them, no enclosing array. JSON Lines is convenient for very large datasets because it can be processed line-by-line without loading the whole file into memory. If you need JSON Lines, post-process the array output by joining the rows with \n and stripping the outer brackets.

Can I convert JSON back to CSV?

This tool only converts CSV to JSON. The reverse direction is a different problem (JSON to CSV) and would need a separate tool. The basic idea is: read the JSON array, walk the union of keys across all objects to determine the column set, then write a header row followed by one row per object.

Is the output valid JSON?

Yes. The output is produced by JSON.stringify, which is the canonical JavaScript JSON serializer. The result is valid against RFC 8259 / ECMA-404 and parseable by every standard JSON parser. The pretty-output toggle switches between 2-space indented and compact whitespace, both are valid JSON.

What if my CSV has a BOM or weird encoding?

The parser operates on the text after the browser has decoded it. UTF-8 with a BOM is supported by every modern browser; the BOM is typically stripped automatically when the text is read into a string. If you see an invisible leading character in the first header, the BOM was probably not stripped, re-save the file as UTF-8 without BOM and re-paste.

Does the converter support Excel-style CSV quirks?

The parser handles the RFC 4180 core: quoted fields, embedded commas, escaped quotes, and multi-line cells. It does not handle Excel-specific quirks such as leading equals signs (which Excel interprets as formulas), single-quote-anchored strings, or locale-specific date formats. If you need those, clean the file in Excel or a CSV-aware tool first.

References

  • RFC 4180, Common Format and MIME Type for Comma-Separated Values (CSV) Files. The IETF specification that defines the CSV format used by this converter. Defines the syntax for records, fields, the double-quote escaping rule ("" โ†’ "), and the optional header row. Authored by Y. Shafranovich in 2005.
  • RFC 8259, The JavaScript Object Notation (JSON) Data Interchange Format. The IETF specification for JSON, authored by T. Bray in 2017 and now standardised as IETF STD 90. Defines the two structural characters (object and array), the seven literal tokens, and the encoding requirements.
  • ECMA-404, The JSON Data Interchange Format. The ECMA international standard that pairs with RFC 8259. Defines the same grammar but as a programming-language-agnostic specification. Often easier to cite than the RFC for cross-language work.
  • IETF STD 90. The Internet Standards Track designation of RFC 8259, confirming JSON as a fully standardised Internet format rather than an informational one.
  • json.org. The original JSON reference site authored by Douglas Crockford, who introduced JSON in 2001. Contains the canonical grammar diagram and links to language parsers.
  • WHATWG HTML Living Standard, Section on CSV-like parsing. The HTML standard includes a note about CSV parsing that influenced the design of many modern parsers, including the one in this tool.