How to Convert CSV to JSON Without Losing Commas, Quotes, or Types
Learn how to convert CSV to JSON reliably: handle quoted commas and escaped quotes, preserve headers, and decide which values should become numbers, booleans, or text.
Published 2026-10-01 · Updated 2026-10-01 · 5 min read
Converting a CSV file to JSON is straightforward only when every value is simple text. Real exports contain commas inside addresses, quotes in notes, blank cells, dates, identifiers with leading zeroes, and columns whose values look numeric but should remain text. A reliable conversion separates two jobs: parse the CSV according to its quoting rules, then deliberately choose JSON value types.
This guide answers a practical question: how can you convert CSV to JSON without splitting a quoted value at a comma or changing the meaning of the data?
Parse rows before assigning types
CSV is a text format in which each record has fields. RFC 4180 describes the common format: fields separated by commas, optional header rows, and double quotes around fields that contain a comma, quote, or line break. A double quote inside a quoted field is represented by two double quotes. 1
That means this row has three fields, not four:
name,city,note
"Mina Patel","St. John's","Asked for ""email, then call"""
Its parsed values are Mina Patel, St. John's, and Asked for "email, then call". Splitting each line on every comma would incorrectly break the note into two values. Use a CSV parser or converter that implements quoted-field handling; do not use a simple split(",") approach for files that may contain quotes or commas.
Confirm what the first row means
Many exports use the first row as column names, but CSV does not guarantee that a file has a header. RFC 4180 allows either form and notes that the presence of a header can be indicated separately. 1
Before converting, inspect the first two rows:
employee_id,start_date,active
00417,2026-09-15,true
If the first row is a header, a useful JSON shape is an array of objects:
[
{
"employee_id": "00417",
"start_date": "2026-09-15",
"active": true
}
]
If the file has no header, obtain trustworthy names from the export documentation or create neutral names such as column_1, column_2, and column_3. Do not guess a business meaning for an unlabeled column.
Preserve text that only looks like a number
JSON supports strings, numbers, objects, arrays, true, false, and null; JSON numbers do not preserve formatting such as leading zeroes. 2 3
Treat identifiers as strings even when their characters are all digits. Postal codes, account numbers, order numbers, phone numbers, and 00417 are labels, not quantities to add. Converting 00417 to the JSON number 417 permanently drops the leading zeroes.
Use an explicit rule for each column:
- Keep identifiers, codes, dates, phone numbers, and free text as strings.
- Convert a value to a number only when the column represents a quantity and the source format is unambiguous.
- Convert
trueandfalseto JSON Booleans only when those exact values are the documented convention for the column. - Decide whether an empty CSV field means an empty string,
null, or an omitted property before converting. Those choices are different in JSON.
For example, an empty middle_name may reasonably become "", while an absent completed_at value may be better represented as null. The correct choice depends on the system that will receive the JSON.
Check row length and duplicate headers
Before exporting JSON, compare the number of parsed fields in each row with the number of headers. A short row may represent a missing final value; a long row can signal a delimiter or quoting problem. RFC 4180 says each line should contain the same number of fields and that spaces are part of a field, so trimming every value automatically can change data. 1
Also make headers unique. JSON objects use names for their members, and RFC 8259 says names within an object SHOULD be unique; duplicate names lead to unpredictable behavior among implementations. 4 If an export contains two status columns, rename them with their source context, such as billing_status and shipping_status, before producing object-shaped JSON.
Validate a small sample before processing the full file
Start with a few representative rows, including one with a quoted comma, one with an escaped quote, one blank field, and one value with leading zeroes. Then verify:
- Each JSON object has the expected keys.
- A quoted comma remains inside one string value.
- Quotes are represented as valid JSON string content.
- Identifiers have not lost leading zeroes.
- The receiving application accepts the expected types and field names.
Valid JSON is necessary but not sufficient. JSON syntax can confirm that the text is structured correctly, but it cannot confirm that an API expects employee_id rather than id, or that it accepts a string instead of a number. Check the receiving system’s schema or a known-good example after the conversion.
For non-sensitive sample data, yukt.tools lists CSV conversion and JSON formatting among its online utilities. Keep customer records, credentials, and other confidential exports out of a web-based utility unless you are authorized to share them; use an approved local or internal workflow when the data is sensitive.
A dependable CSV-to-JSON checklist
- Keep an untouched copy of the original CSV.
- Establish the delimiter, encoding, and whether the first row is a header.
- Parse quoted fields rather than splitting lines at commas.
- Make field names unique and preserve the source-column mapping.
- Set type rules per column, especially for IDs and blank values.
- Validate representative converted rows against the receiving system.
- Save the conversion settings with the output so the result can be reproduced.
The safest conversion is not the one that changes the most values automatically. It is the one that keeps CSV syntax intact, makes type decisions visible, and proves a representative result works where the JSON will be used.
Sources
- RFC 4180: Common Format and MIME Type for Comma-Separated Values (CSV) Files — IETF specification for common CSV record, field, and quoting conventions, accessed 2026-10-01.
- RFC 8259, section 3: JSON Values — IETF specification for JSON value types, accessed 2026-10-01.
- RFC 8259, section 6: JSON Numbers — IETF specification for JSON number syntax, accessed 2026-10-01.
- RFC 8259, section 4: JSON Objects — IETF specification for JSON object member names, accessed 2026-10-01.