Converting CSV to JSON: Handling Quotes, Commas, and Edge Cases

2026-06-03 · 5 min read

Splitting a CSV on commas works until a value contains a comma. Here is how real CSV parsing handles the messy cases.

CSV looks trivial — values separated by commas, rows separated by newlines. But the moment a value contains a comma, a quote, or a line break, naive splitting falls apart. Understanding the rules saves hours of debugging.

The quoting rule

Any field may be wrapped in double quotes. Inside quotes, commas and newlines are treated as literal text, not separators. So "Smith, John" is a single field, not two.

Escaped quotes

To include a literal double quote inside a quoted field, it is doubled. The field "She said ""hi""" decodes to: She said "hi". A parser that does not handle this will mangle the output.

Headers become keys

For JSON output, the first row is treated as the column headers, and each subsequent row becomes an object keyed by those headers. So name,age over Alice,30 becomes {"name": "Alice", "age": 30}.

Decide deliberately whether numeric-looking values should stay strings or become real numbers. "007" as a number becomes 7 — fine for quantities, wrong for zip codes and IDs.

Other gotchas

Convert it cleanly

The CSV to JSON Converter handles quoted fields, escaped quotes, custom delimiters, and optional number casting, and lets you download the result as a .json file.

Try the CSV to JSON Converter →