twoodo
/

Home/Tools/Text & developer utilities

CSV to JSON Converter

Parses quoted fields properly, which splitting on commas does not.

CSV is harder than it looks

The obvious approach — split each line on commas — breaks on the first field that contains a comma. The sample above includes "Mathematician, writer" precisely to demonstrate it: a naive parser produces four columns for that row and three for the others.

A real parser tracks whether it is inside quotes. This one does, which means it handles:

  • Commas inside quoted fields
  • Quotes escaped by doubling them — "" inside a quoted field is one literal quote
  • Line breaks inside quoted fields
  • Windows and Unix line endings

Why the semicolon option exists

In countries where the comma is the decimal separator — much of Europe — spreadsheet software exports CSV with semicolons instead, because commas are already spoken for. A file that looks like one giant column is usually this.

Type detection, and when to switch it off

Numeric-looking values become numbers and true/false become booleans, which is usually what you want. It is wrong in specific cases:

  • Postcodes and zip codes. Leading zeros vanish, so 01234 becomes 1234.
  • Phone numbers, for the same reason, and because they often contain a leading plus.
  • Product codes and identifiers that happen to be digits.
  • Version numbers like 1.10, which becomes 1.1.

Turn detection off if any of those are in your data. Silent conversion of identifiers is a classic source of data corruption, and the same problem that makes spreadsheets turn gene names into dates.

What CSV does not carry

There is no type information, no encoding declaration and no schema. A CSV file does not know whether it is UTF-8, which is why accented characters sometimes arrive as mojibake. There is also no official standard, only a widely followed memo — which is why exports from different software differ in small, annoying ways.

Common uses

  • Getting a spreadsheet export into a format an API will accept.
  • Loading data into a script without writing a parser.
  • Inspecting a CSV whose structure you cannot see.
  • Checking whether quoting is correct in a generated file.

Questions people ask

Why not just split on commas?

Because quoted fields can contain commas. The sample data here includes one specifically to show what breaks.

Why is my CSV semicolon-separated?

Because in countries where the comma is the decimal separator, spreadsheet software exports with semicolons instead.

Why did my postcode lose its leading zero?

Type detection turned it into a number. Switch detection off for postcodes, phone numbers, product codes and version numbers.

How are escaped quotes handled?

A doubled quote inside a quoted field is treated as one literal quote, which is the standard convention.

Is my data uploaded?

No. It is parsed in your browser, which matters because CSV exports usually contain real records.

Your text stays in the page

This matters more here than on most tools. People paste API keys into hash generators, customer data into CSV converters, contract wording into diff checkers and configuration into JSON validators. Almost every site offering these sends your input to a server to process it.

Nothing here is transmitted. The work happens in your browser, this site is static files with no server behind it, and the about page lists every request the site makes, read live from your own browser so you can check rather than trust.