Lesson 3
Quoting, Commas, and Line Breaks
Handle real CSV fields that contain commas, quotes, and line breaks.
Real CSV fields can contain commas:
id,note
1,"hello, world"
The comma inside quotes is data, not a delimiter. The same applies to line breaks inside quoted fields:
id,note
1,"first line
second line"
A correct parser treats that as one row with a multiline field.
Quotes inside fields
CSV normally escapes quotes by doubling them:
id,note
1,"She said ""ship it"""
That represents the text:
She said "ship it"
Why simple split code fails
line.split(",") fails when fields contain quoted commas or line breaks. That is fine for toy examples, but unsafe for real spreadsheet exports.
Key takeaway
Use an RFC-aware parser for CSV. If a conversion breaks, first check quotes around fields with commas, quotes, or line breaks.
Paste tricky rows into the CSV to JSON / JSON to CSV Converter and inspect the preview before trusting the output.