CSV to JSON Converter

Convert CSV text into a JSON array of objects. Everything runs in your browser.

Advertisement

What happens to each line

The first line is read as the field names, with surrounding spaces trimmed, and every line after it becomes one object whose keys are those names. The result is a pretty-printed array, indented so it can be pasted into a code editor, an API client or a configuration file without reformatting. Nothing is inferred beyond that: the structure of the output follows the structure of the input exactly.

The usual reasons to run this conversion are seeding a database from a spreadsheet, turning an exported contact list into fixtures for a test suite, and handing a non-technical colleague's CSV to an endpoint that expects a JSON body. Because the work happens in the browser, the rows never leave your machine, which matters when they contain customer data.

What happens to quoted fields

This converter splits each line on commas, which is the simple approach and is correct for most exported files. It is not a full RFC 4180 parser. When a cell contains a comma and is wrapped in quotes, as a compliant CSV would write it, the split still cuts inside the quoted text: the columns to its right shift one place and any extra cells are dropped because there are now more values than headers. A cell containing a line break is worse, because it becomes two rows and every row after it is misaligned.

If the file has commas inside values, export it again with a semicolon or tab delimiter and convert that, clean the offending cells first, or use a real CSV parser in code. The JSON to CSV converter in this set does quote correctly in the other direction, so files it produced will come back through here intact as long as the values did not contain commas to begin with.

Types, duplicate headers and other details

Every value comes out as a string. A price column of 19.99 becomes "19.99", and an empty cell becomes an empty string rather than null. That is deliberate: guessing types turns a postal code like 02134 into 2134 and destroys it. Cast the fields you need after parsing, in whichever language consumes the JSON, and treat the empty string as your missing-value marker.

Two headers with the same name will overwrite each other, because an object cannot hold one key twice, so rename duplicates before converting. A trailing blank line is ignored. If the file begins with a byte order mark, the kind Excel adds when saving as UTF-8, the first header carries an invisible character and the key will not match what your code expects; strip the mark first. A file with no header row will treat its first data row as the header, so add one before pasting. If you only need to inspect or tidy the JSON after converting rather than reshape it, the JSON formatter indents and validates it without altering any value.

An example: a subscriber export

A newsletter export has four columns, name, email, plan and signup_date, and three subscribers. The header line becomes the keys, and each of the three lines below becomes an object with four string fields, dates included exactly as the spreadsheet wrote them. One subscriber has no plan, so that object carries an empty plan value that your import script can map to a default tier. The result is an array of three objects ready to post. If one subscriber were recorded as Patel, Asha with a comma, this splitter would push the remaining fields one place to the right and the email would end up in the plan column, which is precisely the failure the quoting section describes.

Frequently asked questions

No. The converter splits on every comma, so a quoted value containing a comma will shift the columns after it. Export with another delimiter or clean those cells first.
No, every value stays a string. That avoids corrupting values with leading zeros. Cast the fields you need after parsing.
The first data row is used as the headers and disappears into the keys. Add a header line before pasting so no record is lost.
Excel often writes a UTF-8 byte order mark at the start of the file, which becomes part of the first header. Re-save without the mark or delete the stray character before converting.