Nimble Toolbox

Convert CSV to JSON

Drop a CSV file or paste the text, and the JSON appears at once as an array with one object per row. The delimiter is detected for you, and the file stays in your browser rather than going to a server.

How to use it#

  1. Drop a .csv file on the box, or paste the CSV, or a few rows of it to check the shape first.
  2. Confirm the delimiter and whether the first row holds field names, and tick Nest dotted column names if a header like address.city should become an object.
  3. Copy the JSON, or download it as a .json file named after the one you dropped.

Why splitting on commas is not enough#

The reason CSV parsing is harder than it looks is that a comma inside a quoted field is data, not a separator. A row reading "Smith, John",42 has two fields, and any parser that splits on commas produces three. The same applies to line breaks: a quoted field can contain one, so a CSV file does not have one record per line.

Quotes themselves are escaped by doubling them, so a field containing the word "hi" in quotation marks is written as "She said ""hi""". This converter follows RFC 4180 and reads all of these correctly, which matters mostly for data that came out of a spreadsheet, where free-text columns are full of commas and quotes.

If no field in your file holds a comma, a quote, or a line break, splitting on commas would give the same answer. It is the one awkward row in ten thousand that makes the difference, and that row is usually somebody’s address.

What the type conversion will and will not change#

With conversion on, a field reading 42 becomes the JSON number 42 rather than the string "42", and true and false become booleans. Empty fields become null, because CSV has no way to distinguish an empty string from a missing value and null is the more useful of the two readings.

Two cases are deliberately left as strings. A value with a leading zero, such as 007 or a postcode like 01234, is almost always a code rather than a quantity, and converting it would silently delete the zero. So is a number with more digits than a JSON number holds, such as an integer longer than about sixteen digits or 0.12345678901234567890, because converting would quietly change the last few digits. Long account numbers and identifiers fall into this second category.

If you want everything left alone, turn the conversion off and every value comes through as a string.

Ragged rows and repeated headers#

Real exports are not always rectangular. A row with fewer fields than the header gets the missing ones filled with null rather than left out, so every object in the array has the same keys and nothing downstream has to check whether a property exists. Extra fields beyond the header are dropped, since there is no name to give them.

Duplicate column names get a number appended, so a header of id,id,id produces id, id2, and id3. A blank header cell is named after its position, such as column2. Both of these are more useful than the alternative, which is an object where later columns quietly overwrite earlier ones.

Frequently asked questions#

Why is my number still a string?

#

Two values are left alone on purpose. Anything with a leading zero, because converting 007 to 7 destroys a code that was meant to keep its zeroes. And any number with more digits than JSON can represent exactly, such as an integer beyond about sixteen digits, because conversion would change the digits at the end. Everything else that looks numeric becomes a number.

Does it handle semicolons and tabs?

#

Yes. The delimiter is detected by looking at which candidate appears most often outside quoted fields, which gets a TSV file and a semicolon-separated export from a European locale right. You can also set it explicitly if the guess is wrong.

Is there a size limit?

#

Only your browser’s memory, since the conversion happens on your own machine. Files of a few megabytes are fine, dropped or pasted. Something very large is better handled by a script, because the whole result has to fit in the page.

Is my data uploaded?

#

No. A dropped file is read and parsed by JavaScript in this tab and never leaves it, which matters when the CSV holds customer records.

Can I convert an Excel file?

#

Not on this page, which reads text. An .xlsx workbook is a zipped set of XML files, so use the Excel to JSON converter, which reads every sheet directly. Or save the sheet as CSV from Excel and drop that here.

Can columns become nested objects?

#

Yes. Tick Nest dotted column names and a column called address.city becomes {"address": {"city": ...}} in each record, so a flat export can turn back into the nested JSON it came from. A name that would collide, such as a column called address beside one called address.city, stays as it is so that neither value is lost. The JSON to CSV converter does the reverse when it flattens nested objects.

What happens to a row with too few columns?

#

The missing fields are set to null so that every object has the same keys. Fields beyond the end of the header row are dropped, because there is no name to store them under.