CSV and JSONL traps — quotes, newlines and nested fields
In CSV a comma inside quotes does not split a field; in JSONL a line is one value.
The short answer
Read CSV by RFC 4180 so quoted commas, newlines and quotes stay inside one field, and read JSONL one JSON value per line, transforming by path.
The three CSV traps
Most accidents happen in these three places.
- A comma inside quotes: "Seoul, 3F" is one field. Splitting on commas shifts every column after it.
- A newline inside quotes: a note with a line break spans several physical lines, so reading line by line breaks the record.
- A quote inside a value is written as "" (doubled).
Delimiter and header
The delimiter is chosen by counting commas, semicolons, tabs and pipes in the first lines, which also catches European semicolon CSV.
With a header, the first row becomes column names and data starts on row two. Without one, columns are c1, c2 and column-name rules cannot apply.
JSONL structure
Each line must hold one JSON value. Nested objects are flattened to paths such as user.email or items[0].phone, and each leaf is checked.
Array items are handled by path. Numbers are checked as text and restored as numbers when possible; a non-numeric masked result becomes a string, so check the type.
What re-serialisation changes
JSONL is rewritten line by line, so key order and spacing may change. The meaning is preserved, but a byte-level diff against the original will show differences.
Example
The second record's note contains a comma and a newline. Paste it as is to see.
order_id,customer_name,email,note
1001,Kim Test,user01@example.invalid,first order
1002,Lee Sample,user02@example.invalid,"packing request:
do not leave at the door"
Questions
What if the wrong delimiter is detected?
Fields merge or split and columns shift. Compare the column count in the output with the stats and set the format manually if needed.
Are blank lines allowed in JSONL?
Blank lines are kept and skipped. A line that is not JSON stops the run and reports its line number.
Can I paste pretty-printed JSON?
JSONL requires one value per line. Minify the document first.
Sources
Every example here can be pasted into the workbench as it is.
Open the workbench