How to convert CSV to JSON
CSV is the format spreadsheets speak, JSON is the format code speaks. Converting means turning rows into objects — and handling the quoting quirks that break naive converters.
From spreadsheet to structured data
First row is the field names
A CSV file is a table, and a JSON array of objects is the same table in a different shape. Converting means reading the first row as the field names, then turning every following row into one object whose keys are those names. Three data rows become three objects, each with the same keys — the shape APIs and JavaScript code expect.
Immediately usable in code, APIs and databases
The output is immediately usable: paste it into a JavaScript file, send it to an API that accepts JSON, load it into a database that imports JSON documents, or use it as test data. It is also easy to reshape from here — filter the array, pick out one field, or nest it under another object, all with a few lines of code.
The CSV quirks that break naive converters
Quoted commas are one field, not two
Real-world CSV is messier than the textbook version. Fields that contain commas are wrapped in quotes, and a converter must honour those quotes: "Laptop, 15 inch" is one field, not two. A quote inside a quoted field is written doubled, and the parser must turn it back into a single quote. Line breaks inside quoted fields are kept as part of the field, not treated as row breaks.
Windows line endings and trailing blank lines
Files saved on Windows end their lines with a carriage return plus a newline, and files from other systems use a newline alone — a good converter accepts both. Trailing blank lines at the end of the file are ignored, and empty fields become empty strings rather than errors. A converter that splits on commas and newlines without understanding quotes will mangle all of this, silently.
Types: everything is a string
CSV carries no type information, so every value comes out as a string in the JSON: a price of 899 becomes the string "899", not the number 899, and true becomes the string "true". That is deliberate — guessing types would silently change your data, and a value like 00123 or 2024-01-05 would be mangled by any guesser.
Convert values to numbers in your own code after importing, where the conversion is visible and under your control. A single mapping step — parse the fields you know are numbers, leave the rest as strings — is explicit, reviewable, and does not surprise you three months later.
Convert CSV to JSON in the browser
- Open the CSV to JSON Converter and paste your CSV into the Input box. The first row must be the header row.
- Click Convert to JSON. Each following row becomes one object, with the header names as its keys.
- If a row has the wrong number of fields, the error names the row — fix it in the input and convert again.
- Check the object and field count in the success message.
- Click Copy output or Download to save the JSON, then use it in your app, API test or config file.
Fixing a row that fails
The most common failure is a row with the wrong number of fields: a missing comma, or a quote that was opened and never closed, so the rest of the row collapses into one field. A good error message names the row number and tells you how many fields it found versus how many the header has, so you can jump straight to the problem instead of counting commas by eye.
If the whole file fails with an unclosed-quote error, the culprit is usually a single stray quote mark somewhere in the middle — often in a product name or a note written by hand. Find it, remove it or quote the field properly, and the file will convert.
Using the JSON afterwards
The output is a JSON array of objects, ready for the usual destinations. In JavaScript, fetch it or import it and work with the array directly. For an API test, paste it into the request body. For a config file, save it as .json and load it at startup. For a database that imports JSON documents, the array is already in the right shape.
If you need the data back in a spreadsheet later, the trip reverses cleanly with our JSON to CSV Converter — with the caveat that numbers stay strings on the round trip, because CSV never knew they were numbers.
Related guides
- How to Convert JSON to CSV — turn a JSON array into a spreadsheet-ready CSV.
- How to Format XML — indent XML and check it is actually valid.
- How to Escape HTML (Free HTML Entity Encoder) — turn code characters into entities a browser displays as text.
Questions people ask
What if a row has the wrong number of fields?
The conversion stops with an honest error naming the row and the field counts. Fix the row in the input — usually a missing comma or an unclosed quote — and convert again.
Are numbers kept as numbers?
No. CSV has no type information, so every value becomes a string in the JSON. Convert values to numbers in your own code after importing, where the conversion is visible.
Can I convert a CSV without headers?
No. The first row is always treated as the field names. If your file has no headers, add a header row first, or the first data row will be used as the names.