How To Convert CSV To JSON Without Breaking Quoted Fields
6 min read

A spreadsheet export can look simple until a customer's address contains a comma or a notes cell contains a line break. If you split the text at every comma, one record becomes several fields. If you split it at every newline first, one note can become several records.
To convert CSV to JSON safely, parse the CSV's structure before you build the JSON. Decide how headers and data types should work, then compare the result with the original records.
Inspect The Export Before Converting
Open a small sample and check its delimiter, header row and quoting. CSV commonly uses commas, but spreadsheet exports can use other delimiters. A semicolon-separated file needs a parser that understands that delimiter; changing the filename does not change its structure.
The common format documented in RFC 4180 permits an optional header and expects the same number of fields in each record. Spaces are part of a field. Decide whether your data needs them before trimming every value automatically.
Use a copy of the export for testing. If it contains personal or confidential information, keep it in an approved environment. A page's claim that processing stays in the browser is a product claim; confirm the tool's handling before using sensitive data.
Understand The Quoted-Field Rules
A field containing a comma, line break or double quote should be enclosed in double quotes. Inside a quoted field, a double quote is represented by two double quotes.
For example, the CSV record "Alex","Works in sales, operations and support" has two fields, not four. The comma inside the second field is part of its value.
A field written as "Said ""hello"" yesterday" contains the value Said "hello" yesterday. The doubled quotes represent a quote character; they are not two separate values.
A line break inside a quoted field belongs to that field. That is why a parser must track whether it is currently inside quotes before it treats a comma or a record separator as structural.
Do not try to fix this with a chain of split operations. A CSV parser is responsible for the quoting rules; JSON serialization is responsible for encoding the resulting values. Those are separate jobs.
Choose How Headers Become Keys
If the first row contains column names, use those names to map each record into an object. A header row of name,role and a record of Alex,Designer can become an object with name and role properties.
Check the headers before conversion. Duplicate header names cannot identify separate object properties reliably: when they become object keys, later values overwrite earlier ones. Blank header names get placeholder keys like column_2 in this converter, which is readable but meaningless. Rename problem headers in the source copy before you depend on the output.
If the file has no header, do not accidentally turn the first data row into property names. Use an array representation or supply the field names your receiving system expects. A header checkbox is a decision about the data, not a setting to leave on without looking.
Keep field counts consistent. A short record can mean an intentionally empty value, a malformed export or a parsing mistake. Investigate it rather than silently dropping the extra or missing information.
Decide Which Values Stay Text
CSV does not provide the type system your application expects. The text 00127 may be an identifier, not the number 127. A date may depend on a locale-specific format. An empty field can mean empty text, missing information or something else defined by the receiving system.
Keep identifiers and ambiguous values as text until you have a deliberate mapping. Convert numbers, dates and booleans only when you know the required format and what should happen when a value does not match it.
For example, if a column is a postal code, preserving the leading zero can be essential. A conversion that produces valid JSON while dropping that zero is still wrong for the task.
Write down the expected output shape before importing it elsewhere: an array of objects, an array of arrays or another structure. Valid JSON is a syntax result, not a guarantee that the destination understands the fields.
Validate With Known Edge Cases
Test a small sample that includes a plain record, a comma inside a cell, a quote inside a cell, a multiline note and an empty field. Compare the values after conversion with the values you intended to preserve.
Count the records rather than the lines in the source text. A quoted multiline note makes those counts different. Check that every output record has the expected fields, and inspect the first and last records as well as the edge cases.
Parse the JSON with a JSON parser before using it downstream. Then test it against the destination's requirements. Syntax validation can catch broken quoting; it cannot tell you that you used the wrong header or converted an account code into a number.
For a large or irregular export, stop at the first unexplained mismatch. Repeating the conversion across the full file only multiplies the cleanup. Fix the mapping or export format, rerun the small sample and expand once the sample is correct.
The CSV to JSON converter on DigitalDecided turns each record into an object keyed by the header row when you tell it the first row contains headers. Know its exact behavior before you rely on the output. Every value comes out as a string, so "42" is text until you convert it yourself. Blank headers are trimmed and replaced with column_N placeholders. If a row is ragged, the tool warns you; missing values come out empty and extra values can be dropped. Unclosed quotes are not reliably rejected, so check your quoting in the source when a result looks wrong.
That behavior list is why the verification step is not optional: check header uniqueness, record counts and quoting manually. Valid JSON is proof the output parses, not proof the CSV was read the way you meant.
Paste your sample, choose whether the first row contains headers, and copy or download the result. Compare it against the source records, fix the mapping or the export, and rerun until the small sample is right before converting the full file.
