CSV to JSON for Every Role: 6 Real Uses, Made Easy cover image
Prateek Zare

Written by Prateek Zare

Software Developer with ML and Data Expertise, 8+ years of experience

Last updated
Developer Tools

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.

The short answerFor csv to json in most cases, use array of objects for APIs, fixtures and charts. Use array of arrays when column names do not matter. Use keyed by first column for lookups. Turn type inference on for numbers and booleans, and off for IDs, ZIP codes and phone numbers. The CSV to JSON converter has all of these switches.

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,,false

Array 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.

The three csv to json output shapes
ShapeWhat csv to json gives youBest for
Array of objectsOne object per row, keys taken from the headerAPIs, fixtures, chart libraries
Array of arraysRows as plain lists with no keysMatrix maths, positional data, files without useful headers
Keyed by first columnThe first column becomes the key of each entryLookups 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.

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.

Shape by receiver for csv to json
ReceiverWantsPickReason
REST API bodyList of records with named fieldsArray of objectsField names make the payload self describing
Chart libraryLabels and seriesArray of objectsEach row maps to one point
Spreadsheet like grid componentRows and columns by positionArray of arraysNo repeated key names, smaller output
In page search by IDFast access to one recordKeyed by first columnDirect lookup instead of a loop
Config or translation fileKey to value pairsKeyed by first columnOne 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.

What csv to json does to common cell values
CSV cellInference onInference offRisk
trueBoolean trueTextNone
42Number 42TextNone
042Number 42Text 042Leading zero lost
12.50Number 12.5Text 12.50Trailing zero lost
+44Number 44Text +44Plus sign lost
1e5Number 100000Text 1e5Product code mangled
0x1ANumber 26Text 0x1AHex code mangled
2024-03-01TextTextDates are never converted
Codes are not numbers in csv to json

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 by source for csv to json
DelimiterTypical sourceSign you picked wrong
CommaUS and UK spreadsheets, most exportsEverything lands in the first key
SemicolonSpreadsheets with a decimal commaNumbers split into two columns
TabDatabase tools, copied cellsOnly one column appears
PipeLegacy systems, logsOnly 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

Five minute csv to json data check

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.

A shop exports SKU 00417. You want the JSON to keep it exactly. What do you do?

With inference on, 00417 passes the number test and becomes 417. Turning inference off keeps every value as text, so the leading zeros stay.

Which shape suits a script that must find one record by its ID instantly?

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

  1. 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.
  2. Set the delimiter and headerChoose comma, semicolon, tab, pipe or a custom character. Keep first row is header on unless the file has none.
  3. Choose the output modeArray of objects, array of arrays, or keyed by first column. Use the table above to decide.
  4. Set the cleaning optionsTick trim whitespace, skip empty rows and empty as null where they fit. Decide on inference using the label test.
  5. 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 Converter

Questions 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