CSV to JSON: Simplifying Web Data Imports
In this guide
CSV is the lowest common denominator of data exchange: every spreadsheet can export it. JSON is what most web code wants. Converting between them is straightforward in principle, but real CSV files are full of small traps.
How the conversion works
The first row usually holds column names. Each following row becomes a JSON object whose keys are those names, and the whole file becomes an array. A file with columns name, age and city produces objects such as name, age and city, one per row.
Delimiters, quotes and line breaks
Despite the name, not every CSV uses commas; semicolons are common in regions where the comma is the decimal separator, and tabs are used too. Fields containing the delimiter or a line break must be wrapped in double quotes, and a quote inside a field is written twice. A parser that ignores these rules splits one value into two.
Types are not preserved
CSV has no types; everything is text. A converter may keep numbers as strings or guess. Values with leading zeros, like postcodes 02134 or phone numbers, must stay as text or the zero disappears. Large IDs can lose precision if turned into numbers.
Encoding and headers
Files exported from spreadsheets may have a byte order mark at the start or use a legacy encoding, which shows up as odd characters in the first column name or in accented letters. Save as UTF-8 where possible. Duplicate or empty header names create colliding or missing keys.
Check the result
Count the rows before and after, scan a few records, and watch for empty strings that should be null. Process the data in your browser if it contains personal information.
Worked example: two rows and a tricky field
The CSV name,age / John,30 / Asha,28 converted to a JSON array of two objects, each using the header names as keys, with age as the numbers 30 and 28 because type detection was on. A second test with the row "Smith, J",007 kept the comma inside the quotes, so the name stayed Smith, J, and the 007 stayed the text "007", with its leading zeros intact.
That last detail is the reason to look at your output: identifiers such as phone numbers and postcodes should stay text, and the tool preserves values with leading zeros. If your data uses a delimiter other than a comma, set it in the delimiter option instead of leaving it on auto.
Key Takeaways
- Header row becomes the keys.
- Check the delimiter and quoting rules.
- Keep leading zeros and long IDs as text.
- Use UTF-8 and compare row counts.
Frequently Asked Questions
Why are my accented characters wrong?
The file is probably not UTF-8. Re-save it as UTF-8 and convert again.
Why did my leading zero vanish?
The value was parsed as a number. Keep the column as text.
Can CSV hold nested data?
Not naturally. JSON can nest, so converting back and forth needs a convention.
Free tools mentioned in this guide
Browse every Converter Tools utility, or see all tools.