2 min read
CSV to JSON Conversion, Without Breaking Your Data
How CSV quoting and escaping work, how values map to JSON types, and how to convert both directions without mangling commas, quotes, or newlines.
Why CSV is trickier than it looks
CSV looks like a simple grid of values separated by commas, but the format has rules that trip up naive splitting. A field can itself contain a comma, a line break, or a double quote. To handle that, CSV wraps such fields in double quotes, so New York, NY becomes a single quoted field rather than two columns.
Inside a quoted field, a literal double quote is escaped by doubling it. If you split a CSV file on commas with a plain string split, any quoted comma or escaped quote will shift every column after it, silently corrupting the row.
How CSV values become JSON
JSON has real data types: strings, numbers, booleans, null, arrays, and objects. CSV has none of that. Every field in a CSV file is just text. A converter has to decide whether the text 42 should become the JSON number 42 or the JSON string 42, and whether an empty cell should become an empty string or null.
A common and safe default is to keep everything as strings unless a value clearly parses as a number or boolean. That avoids surprises such as a ZIP code like 07030 losing its leading zero when treated as a number, or a product code like 1E5 being read as scientific notation. When precision matters, keeping the raw text is the correct choice.
The first row of most CSV files is a header. Converters use those header names as the JSON object keys, turning each subsequent row into one object. A file with 500 data rows becomes a JSON array of 500 objects, each sharing the same keys.
Converting a file step by step
The tool runs entirely in your browser, so your data is never uploaded to a server. That matters when the CSV contains customer records, internal metrics, or anything you would not paste into a random website.
- 1Paste your CSV text or drop the file into the input area.
- 2Confirm the delimiter is a comma; switch it if your file uses semicolons or tabs.
- 3Check that the first row is detected as the header, so keys come from column names.
- 4Choose whether numbers and booleans should be typed or kept as strings.
- 5Read the JSON output and copy it, or paste JSON in the other direction to get CSV back.
Going back from JSON to CSV
The reverse direction flattens an array of objects into rows. The union of all keys becomes the header row, and each object supplies one data row. If some objects are missing a key, that cell is left empty rather than dropped.
When writing CSV, the converter re-applies quoting: any value containing a comma, a double quote, or a newline is wrapped in double quotes, and internal quotes are doubled. This round-trip safety means you can convert CSV to JSON, edit it, and convert back without the delimiters in your data corrupting the file.
Frequently asked questions
What happens to a value that contains a comma?
In CSV it must be wrapped in double quotes so the comma is treated as text, not a column break. A good converter reads that quoting correctly and, when writing CSV back, re-adds the quotes automatically.
Why did my ZIP code or phone number lose its leading zero?
That happens when the converter treats the field as a number, and numbers have no leading zeros. Keep such columns as strings so the exact text is preserved.
Is my data uploaded anywhere?
No. The conversion runs locally in your browser, so the CSV and JSON never leave your machine.
Tools mentioned in this guide
CSV to JSON Converter
Convert CSV to JSON and JSON back to CSV — quotes and commas handled properly.
Developer Tools
JSON Formatter
Format, validate, and minify JSON with precise error locations.
Developer Tools
JSON to TypeScript Converter
Paste JSON, get clean TypeScript interfaces — nested objects and arrays typed.
Developer Tools
Base64 Encoder / Decoder
Encode text to Base64 or decode it back — full Unicode support.
Developer Tools
Text Diff Checker
Compare two texts and see every added and removed line highlighted.
Text Tools
Keep reading