CSV to JSON for Every Role: 6 Real Uses, Made Easy
CSV to JSON sounds like one job, yet a tester, an analyst and a shop owner need three different results from the same file. The right output shape and one checkbox decide whether your data arrives clean or quietly damaged. Good csv to json work is mostly about those two choices.
Below you will find one sample file, the exact JSON it produces under each setting, and six role based playbooks for csv to json work. Skip to your role if you are in a hurry.
What CSV to JSON conversion changes
CSV is a grid of text. Every cell is a string, and the file has no idea whether 42 is a number or a label. JSON adds structure and types: objects, arrays, numbers, booleans and null. Conversion is the act of guessing those types and choosing a shape, and every csv to json tool does both.
Here is a small file with a trap in it, a perfect test for csv to json settings. The first customer has a comma inside the name, a leading zero in the ID, and the second customer has an empty balance.
Sample CSV for the csv to json test
id,name,city,balance,active
001,"Smith, John",Berlin,1200.50,true
002,Ana Lopez,Madrid,,falseArray of objects, type inference on, empty cells as null
[
{"id": 1, "name": "Smith, John", "city": "Berlin", "balance": 1200.5, "active": true},
{"id": 2, "name": "Ana Lopez", "city": "Madrid", "balance": null, "active": false}
]Array of objects, type inference off
[
{"id": "001", "name": "Smith, John", "city": "Berlin", "balance": "1200.50", "active": "true"},
{"id": "002", "name": "Ana Lopez", "city": "Madrid", "balance": "", "active": "false"}
]Notice what moved. With inference on, 001 became 1 and 1200.50 became 1200.5. With it off, every value stays text, which is safe but means your code must convert numbers later. Neither csv to json result is wrong. Each fits a different job.
| Shape | What csv to json gives you | Best for |
|---|---|---|
| Array of objects | One object per row, keys taken from the header | APIs, fixtures, chart libraries |
| Array of arrays | Rows as plain lists with no keys | Matrix maths, positional data, files without useful headers |
| Keyed by first column | The first column becomes the key of each entry | Lookups by ID, SKU or country code |
Six real jobs, by role
Pick the tab that looks like your day, then see how csv to json fits it. Each one names the task, the setting to choose and the mistake to avoid.
Task: you need 50 rows of realistic data for a table component before the backend exists. Export a spreadsheet to CSV, run csv to json, and import the JSON file as a module.
Settings: array of objects, type inference on, trim whitespace on. Components usually sort prices and counts as numbers, so real numbers matter.
Watch for: boolean looking text such as TRUE from a spreadsheet. The tool matches the exact words true and false, so check how your export writes them.
Task: build fixtures for edge cases. One row per case: empty name, very long name, negative amount, a name with a comma, a name with a quoted word.
Settings: array of objects, empty as null on, and run a second pass with inference off. Comparing both outputs shows how your code reacts to numbers arriving as text.
Watch for: IDs with leading zeros. Test them with inference off, because that is how many legacy systems send them.
Task: a BI export arrives as CSV and a charting library wants an array of objects. Run csv to json, then feed the result straight in, or open the file in the data visualization tool to check the shape of the trend first.
Settings: array of objects, inference on, skip empty rows on. Dates stay as strings, which is what most chart libraries expect.
Watch for: a footer line such as Total at the bottom of the export. It becomes a real record, so delete it before converting.
Task: seed a database or call a bulk endpoint with data from a partner. The partner sends semicolons because their spreadsheet uses a decimal comma.
Settings: delimiter set to semicolon, array of objects. Then run the result through the JSON formatter to read it before posting.
Watch for: decimals written as 12,50. With a semicolon delimiter this stays a string, because 12,50 is not a number in JavaScript. Replace the comma before converting if the API wants a number.
Task: a product list lives in a spreadsheet and the webshop import wants JSON. Save the sheet as CSV first. If you only have an Excel file, the Excel to CSV converter does that step.
Settings: array of objects, type inference off. SKUs such as 00417 and phone numbers such as +4930123456 are labels, not quantities.
Watch for: with inference on, 00417 turns into 417 and +4930123456 turns into 4930123456. The shop then cannot match the product.
Task: survey answers need to go into a small script or a notebook. The first column holds a respondent code, and you want to find any respondent fast.
Settings: keyed by first column. The script can read one respondent by code without scanning a list.
Watch for: duplicate codes in the first column. Two rows with the same key cannot both survive in an object, so check the code column for repeats first.
Choosing the output shape for your job
Most people leave the shape at its default and never look back. That works until the data is large or the consumer is picky. Use this table to match the shape to the receiver.
| Receiver | Wants | Pick | Reason |
|---|---|---|---|
| REST API body | List of records with named fields | Array of objects | Field names make the payload self describing |
| Chart library | Labels and series | Array of objects | Each row maps to one point |
| Spreadsheet like grid component | Rows and columns by position | Array of arrays | No repeated key names, smaller output |
| In page search by ID | Fast access to one record | Keyed by first column | Direct lookup instead of a loop |
| Config or translation file | Key to value pairs | Keyed by first column | One column is the key, the rest is the value |
File size is a real consideration. Array of objects repeats every key name in every row. A file with 10,000 rows and 12 columns repeats each header 10,000 times. Array of arrays stores the header once, so it is noticeably smaller, at the cost of readability.
Type inference: when to turn it on or off
Type inference tests each trimmed value in a fixed order. Exact true or false becomes a boolean. Exact null becomes JSON null. Anything that passes a number test becomes a number. All else stays a string.
| CSV cell | Inference on | Inference off | Risk |
|---|---|---|---|
true | Boolean true | Text | None |
42 | Number 42 | Text | None |
042 | Number 42 | Text 042 | Leading zero lost |
12.50 | Number 12.5 | Text 12.50 | Trailing zero lost |
+44 | Number 44 | Text +44 | Plus sign lost |
1e5 | Number 100000 | Text 1e5 | Product code mangled |
0x1A | Number 26 | Text 0x1A | Hex code mangled |
2024-03-01 | Text | Text | Dates are never converted |
If you would never add two values together, they are labels. ZIP codes, phone numbers, order numbers and SKUs belong in strings. Turn inference off, or quote those cells in the CSV before you convert.
Delimiters, quotes and line endings
The name says comma, but real files use whatever the exporting program chose. Spreadsheets in many European locales write semicolons because the comma is already the decimal mark. Database dumps often use tabs or pipes.
| Delimiter | Typical source | Sign you picked wrong |
|---|---|---|
| Comma | US and UK spreadsheets, most exports | Everything lands in the first key |
| Semicolon | Spreadsheets with a decimal comma | Numbers split into two columns |
| Tab | Database tools, copied cells | Only one column appears |
| Pipe | Legacy systems, logs | Only one column appears |
Quotes follow RFC 4180, the closest thing CSV has to a standard. A field with a comma, a line break or a double quote should be wrapped in double quotes. A quote inside such a field is written twice.
Quoting rules in one line each
plain text -> plain text
Smith, John -> "Smith, John"
5" pipe -> "5"" pipe"
line one + line two -> "line one
line two"
A checklist before you convert
The tool shows rows, columns, key count and output size after each run. Compare the row count with your spreadsheet. A mismatch usually means a stray quote swallowed several lines into one cell.
With inference on, 00417 passes the number test and becomes 417. Turning inference off keeps every value as text, so the leading zeros stay.
Keyed by first column builds an object where the ID is the key, so the script reads the record directly instead of looping over a list.
Convert a file step by step with csv to json
- Load the csv to json dataPaste the text, pick a sample, or choose a file with Upload. The file is read in your browser and goes nowhere.
- Set the delimiter and headerChoose comma, semicolon, tab, pipe or a custom character. Keep first row is header on unless the file has none.
- Choose the output modeArray of objects, array of arrays, or keyed by first column. Use the table above to decide.
- Set the cleaning optionsTick trim whitespace, skip empty rows and empty as null where they fit. Decide on inference using the label test.
- Convert and copyPress convert, check the counts, then copy the result or download the file. The highlighted view makes errors easy to spot.
Need the reverse trip later? The JSON to CSV converter turns an array of objects back into rows for a spreadsheet.
Try csv to json on your own file now and compare the output under both inference settings. Everything runs in your browser.
Open the CSV to JSON ConverterQuestions people ask about CSV to JSON
What is the difference between CSV and JSON?
CSV is a flat table of text with one record per line. JSON is a nested format with typed values, so it can hold numbers, booleans, null, lists and objects.
Can a CSV field contain a comma?
Yes, when the field is wrapped in double quotes. A converter that follows RFC 4180 keeps the whole quoted text as one value.
How do I keep leading zeros when converting CSV to JSON?
Turn type inference off so every cell stays a string. You can also quote such cells in the source file, though a spreadsheet may strip the zeros before export.
Does the CSV get uploaded to a server?
No. Csv to json parsing and conversion run in your browser with JavaScript, so the data stays on your device.
Why did my semicolon file land in one column?
The delimiter is still set to comma. Select semicolon in the delimiter options and convert again.
What happens to empty cells in csv to json?
They become an empty string by default, or JSON null when you tick the empty as null option.
Can I turn an Excel file into JSON?
Save or convert the sheet to CSV first, then convert that CSV. Check that the file uses the delimiter you expect.
Sources: RFC 4180, Common Format and MIME Type for CSV Files
