DevKitHub

JSON & Data

CSV to JSON Converter (and back)

Paste CSV to get JSON, or JSON to get CSV. Quoted fields, embedded commas and newlines are handled properly, and values that only look numeric stay as text.

3 lines
10 lines

Values only become numbers when converting them back gives the identical string, so 007 and a nineteen-digit id stay as text instead of being silently rewritten.

This tool runs entirely in your browser. Your input is never uploaded, stored or logged.

How it works

CSV cannot be parsed by splitting on commas, which is how most converters do it. A quoted field may contain a comma, a line break, or a doubled quote standing for a literal one, so the format needs a character-by-character scan that tracks whether it is currently inside quotes. Every exported spreadsheet hits this on the first address column, and a splitting parser silently produces a row with the wrong number of fields — which then shifts every subsequent column by one.

Type conversion is where a converter usually destroys data. The rule here is that a value only becomes a number when converting it back produces the identical string. 007 stays text, because Number("007") prints as 7. 1e5 stays text, 1.50 stays text, +1 stays text, and a nineteen-digit account id stays text because it is past the point where a JavaScript number is exact. That single round-trip test is the difference between a tool that converts your data and one that quietly corrupts zip codes and phone numbers.

Going the other way, the header row is the union of every key in first-seen order rather than the keys of the first record. A ragged array — where later objects carry fields the first one lacks — would otherwise lose those columns without a word. Fields are quoted only when they contain the delimiter, a quote or a line break, so the output stays readable, and a nested object is written as JSON rather than as the string "[object Object]".

Common problems

Every example below is run against this tool in our test suite, so what it says here is what the tool actually does.

A quoted field was never closed.

name
"Doe, Jane
Why:
An opening quote with no closing one, usually from a file that was truncated or from text that contained a quote character which was never escaped.
Fix:
Close the quote. A literal quote inside a quoted field is written as two quotes: "She said ""hi""".

Every column after the first is shifted by one.

Why:
A comma inside a value that was not quoted. "Doe, Jane" without quotes is two fields, and the whole row shifts from that point on.
Fix:
Quote any value containing the delimiter. If you are generating the CSV, quote fields rather than hoping they contain no commas.

Leading zeros disappeared from a zip code or product code.

Why:
Most converters call Number() on anything that looks numeric, and 007 becomes 7. The same defect turns version 1.10 into 1.1 and truncates long ids.
Fix:
Nothing to do here — this converter only converts values that round-trip exactly, so 007 stays text. Turn type conversion off entirely if you want every value as a string.

Frequently asked questions

Does it handle commas and line breaks inside values?
Yes. The parser follows RFC 4180: a field wrapped in quotes may contain the delimiter, a line break, or a doubled quote standing for a literal one. This is the part that splitting on commas gets wrong.
Why is my number still a string in the JSON?
Because converting it would have changed it. A value only becomes a number when Number() gives back the identical string, which protects leading zeros, exponent notation, trailing zeros and ids longer than 16 digits from being silently rewritten.
Can I use a semicolon or tab instead of a comma?
Yes, any single character can be the delimiter. Semicolon is common in locales where the comma is the decimal separator, and tab-separated files are handled the same way.
What happens to nested objects when converting JSON to CSV?
They are written as JSON text inside the cell, because CSV has no way to express nesting. Flatten the structure first if you need the nested values as their own columns.

Read more about this

Last updated