CSV has no single owner and no strict standard. RFC 4180 (2005) describes the common format and registers the text/csv type, but it is informational, and it leaves out the things that break files in practice: which character separates fields, which encoding is used, and what a number is. This guide lists the cases where a naive reader loses data, and how to check them.
What RFC 4180 does say
- Each record is one line, ended by CRLF; the last record may omit the final line break.
- Fields are separated by commas. An optional header row comes first.
- A field that contains a comma, a double quote or a line break must be wrapped in double quotes.
- A double quote inside a quoted field is written as two double quotes.
Paste this into the CSV to JSON converter:
name,note
"Smith, J","He said ""hi""
there"
Lee,
It reports two records. The first has the name Smith, J and a note that contains a quote and a line break (He said "hi" then a new line, there). The second has the name Lee and an empty note, which becomes null. A parser that split on every comma and every newline would see five or six broken rows instead.
Edge case 1: line breaks inside fields
Because a quoted field may contain newlines, “one line is one record” is false. Code such as text.split('\n').map(line => line.split(',')) works on tidy exports and fails the day a customer pastes an address with two lines into a form. Use a real parser, and test it with a field that has a newline in it.
Edge case 2: the delimiter is not always a comma
In many European locales the decimal separator is a comma, so spreadsheets write semicolons between fields. The text a;b then 1,5;2 is two columns, with the value 1,5 in the first. The converter’s auto-detect picks the semicolon and keeps 1,5 as text, because it is not a valid number with a decimal point. Tabs and pipes are also common. When a file looks like one wide column, the delimiter is the first thing to check, and the CSV viewer lets you change it and see the columns line up.
Edge case 3: types you did not ask for
Numbers in CSV are text. A converter that guesses types can help or hurt:
007is an identifier, not the number 7. A ZIP code, phone number, order code or product SKU loses its leading zeros if it becomes a number.1E5can be read as 100000, and a long digit string can be rounded to a float. See the guide on big numbers in JSON.true,nulland empty cells have no single meaning across systems.
In the converter above, a column with 007 stays "007" while 1 and 2 become numbers. Switch type detection off and every value stays a string, which is the safe choice when you do not know the schema.
Edge case 4: encoding and the byte order mark
CSV files do not declare their encoding. UTF-8 is the right default, but Excel on Windows may read a file without a byte order mark as a legacy code page and show é instead of é. If your audience uses Excel, write a BOM (the JSON to CSV tool has a switch for it). If the file goes to a command-line tool or a database loader, leave it out, because some readers include the BOM bytes in the first column name.
Edge case 5: formula injection
If a CSV is opened in a spreadsheet, a cell that starts with =, +, - or @ can be treated as a formula. A user-controlled value such as =HYPERLINK(...) in an export is a known attack (OWASP calls it CSV injection). When you generate CSV from user input, prefix such cells with a single quote or a space, or at least warn the person who will open the file. When you convert in the other direction, a value like =SUM(A1) is just text; the converter above returns it unchanged.
Edge case 6: ragged rows and duplicate headers
RFC 4180 says every row should have the same number of fields, but real files do not. A row with fewer fields leaves missing keys; a row with more has nowhere to go. Duplicate header names collide when rows become objects. Look at the record count in the status line after a conversion and compare it with what you expect.
Going the other way
JSON to CSV has to decide how to flatten nested objects (address.city as a column name) and what to do with arrays. Check that the header covers every key present in any object, not only the first one.
A short test set
Keep four lines you can paste into any CSV tool before you trust it: a comma in a field, a quote in a field, a newline in a field, and a value with a leading zero. If all four come out right, the parser is probably sound. Everything here runs in your browser, so the files you try never leave your machine.
Frequently asked questions
How do I put a comma or a quote inside a CSV field?
Wrap the whole field in double quotes. To include a double quote inside it, write the quote twice: "He said ""hi""" is the text He said "hi". This is the rule in RFC 4180 and every serious parser follows it.
Can a CSV field contain a line break?
Yes, if the field is quoted. That means you cannot split a CSV file into records by splitting on newlines; a parser has to track whether it is inside quotes. This is the most common reason a hand-written split() breaks.
Why did my ZIP code 007 turn into 7?
Something converted the text to a number. Spreadsheets do it by default; converters do it when type detection is on. Keep columns that are identifiers as text. The CSV to JSON converter here keeps values with leading zeros as strings.
Why does Excel show broken characters in my UTF-8 CSV?
Older versions of Excel assume a legacy code page unless the file starts with a UTF-8 byte order mark. Add the BOM when the file is for Excel, and leave it out for tools that treat it as part of the first column name.
More guides
- CIDR notation: why a /31 has two usable hosts, what a /32 is for, and the subnet mistakes to avoid
- Hashing is not encryption: what a hash can do, and why passwords need bcrypt
- Unix timestamps: seconds, milliseconds or microseconds, and the dates where they go wrong
- UUID v4, UUID v7 and ULID: which ID to use, and what is inside each
- Base64 is not encryption: what it does, and the bugs it causes
- JSON, CBOR, MessagePack and Protobuf: the same data in four sets of bytes
- Regex backtracking: how one innocent pattern can freeze a server (ReDoS)
- URL encoding pitfalls: %20 or +, double encoding, and the characters that break links
- Cron and time zones: why your 02:30 job runs twice or never
- Why JSON silently changes your big numbers (and how to stop it)
- JWT pitfalls: decoding a token is not verifying it
- YAML surprises: the Norway problem, octal numbers and version strings