Convert CSV to JSON arrays and back, quoted fields supported. Handy for spreadsheets and API data.
Comma-separated values has been used informally for decades and was only formally specified in RFC 4180 in 2005. The rules are short, but they matter the moment your data contains anything other than plain text:
He said ""hi"".According to the specification, a file should not change its delimiter and should not contain spaces between the delimiter and the field. In practice, both happen constantly.
| Problem | Why it happens |
|---|---|
| Wrong delimiter | Many European locales export with semicolons, because the comma is the decimal separator |
| Leading zeros lost | Spreadsheets guess the type and turn 007 into 7 |
| Long numbers mangled | IDs above 15 digits are converted to floats and lose precision |
| Headaches with encoding | A UTF-8 BOM, or a legacy Windows-1252 export, breaks accented characters |
| Line breaks inside fields | Valid CSV, but naive line-by-line parsers split the record in two |
CSV is compact and spreadsheet-friendly but represents only a flat table: no nested objects, no types, no arrays. JSON keeps structure and types but is roughly two to three times larger and does not open directly in a spreadsheet. The practical rule is to use CSV for tabular exports and JSON for anything with hierarchy or mixed types.
When turning JSON into CSV, pad missing keys with empty values so every row has the same column count, and quote every string. When turning CSV into JSON, keep unquoted numeric fields as numbers but be careful with postal codes, phone numbers and account identifiers, which only look numeric and should stay strings.