📊 CSV to JSON Converter
Convert CSV (with a header row) to a JSON array of objects, or a JSON array back to CSV. Handles quoted fields, commas inside quotes, and escaped quotes.
How the CSV is read
The parser walks the text one character at a time, tracking whether it is inside a quoted field. A comma or newline only ends a field or a row when it is outside quotes, and a doubled quote inside a quoted field means one literal quote. The first row becomes the keys:
name,city,note
"Doe, Jane",Boston,"Says ""hi"""
[ { "name": "Doe, Jane", "city": "Boston", "note": "Says \"hi\"" } ]
So the comma inside "Doe, Jane" does not split the row, and the note keeps one pair of quotes rather than two. A newline inside quotes stays in the value, so multi-line cells survive.
What to watch in the output
- Every value is a string. No type guessing happens, so 42 and true arrive in the JSON as "42" and "true". Convert them after parsing if you need real numbers.
- Spaces are part of the data. Writing name, city in the header gives you a key called " city" with a leading space. Strip the padding in the CSV first.
- Short rows are padded, long rows are cut - missing fields become empty strings, and anything past the last header is dropped.
- Blank lines vanish, the trailing newline included, so an empty line never becomes an empty object.
Frequently asked questions
How do I handle a comma inside a CSV field?
Wrap the field in double quotes, as in "Doe, Jane". If the value also contains a quote, double it: "Says ""hi""" is read as Says "hi". These are the rules spreadsheets already use when they export.
Why are my numbers quoted in the JSON?
CSV has no types - every cell is text - and this converter does not guess, so a column of prices comes out as strings. That is deliberate: guessing would turn a leading-zero product code like 00734 into 734.
Can it convert JSON back to CSV?
Yes, if the JSON is a non-empty array of objects. The columns are the union of every key seen, in the order they first appear, and missing keys become empty cells. Nested objects and arrays are not flattened - they come out as [object Object] - so flatten them before converting.