Developers · 28 November 2026 · 3 min read

CSV vs JSON: When to Use Which and How to Convert Safely

By

CSV and JSON compared for real work: flat vs nested data, types, encoding and delimiters, file size, and how to convert between them without losing information.

CSV vs JSON: When to Use Which and How to Convert Safely

CSV and JSON are the two formats you meet most when data moves between systems. A shop exports orders as CSV, an API returns them as JSON, and someone in accounting wants them in Excel by lunch. Both formats are plain text and both look simple, but they are good at different things, and converting between them is where data quietly gets damaged. This guide helps you choose and convert with confidence, for example with the CSV to JSON converter.

The core difference: a table vs a tree

CSV is a table. One line per record, one value per column, the first line usually holding the column names:

id,name,city,active
1001,Anna Weber,Berlin,true
1002,"Smith, John",Leeds,false

JSON is a tree. Records are objects, values can be nested, and lists can live inside records:

{"id": 1001, "name": "Anna Weber",
 "address": {"city": "Berlin"},
 "tags": ["vip", "newsletter"], "active": true}

That one difference explains most of the rest. If your data is naturally a table, CSV is compact and every spreadsheet opens it. If a record contains a list (order lines, phone numbers, tags) or sub-records (an address), CSV has no clean place for it.

Side by side

CSVJSON
StructureFlat rows and columnsNested objects and arrays
Data typesNone, everything is textString, number, true/false, null
StandardLoose (RFC 4180 is widely ignored)Strict (RFC 8259)
EncodingWhatever the exporting program usedUTF-8 for data exchange
Size for big tablesSmall, column names appear onceLarger, keys repeat in every record
Opens in ExcelDirectlyNeeds conversion or Power Query
Typical useImports, exports, reportsAPIs, config, app data

CSV’s weak spots: types, delimiters, encoding

Because CSV has no types, the program reading it has to guess. Excel’s guesses are famous: 00123 loses its zeros, 1-2 turns into a date, and a 16-digit card or account number gets rounded. The older guide on opening CSV in Excel covers the import side in detail.

There is also no agreed delimiter. Excel in many European locales saves with semicolons because the comma is the decimal separator there, and data copied from a spreadsheet arrives tab-separated. Values containing the delimiter, quotes or line breaks must be wrapped in double quotes, with inner quotes doubled (""). Hand-written CSV often gets this wrong. Finally, encoding: a file saved by an old program in a Windows code page shows broken accents when read as UTF-8. When you control the export, choose UTF-8.

Converting without losing data

CSV to JSON

  • Decide on types. Automatic type conversion turns 42 into a number and true into a boolean, which is what an API usually wants. Turn it off when columns hold IDs, postcodes or phone numbers with leading zeros. They must stay strings.
  • Watch long numbers. JavaScript and many JSON parsers store numbers as 64-bit floats, which are exact only up to 9,007,199,254,740,991. Longer IDs should be strings.
  • Empty cells. Decide whether an empty cell means null or an empty string, and be consistent; the receiving system may treat them differently.
  • Dates stay text in both formats. Prefer ISO 8601, such as 2026-11-28, which sorts correctly and is unambiguous.

JSON to CSV

Nested data has to be flattened. The JSON to CSV converter turns address.city into its own column and writes arrays as JSON text in one cell, such as ["vip","newsletter"]. Records with missing fields get empty cells. That is fine for viewing and reporting, but if the target system needs one row per order line, you must reshape the data first: one CSV row per item, with the order ID repeated.

Before converting JSON from an API or log, run it through the JSON formatter. If the JSON is invalid, it tells you the exact line and column, which is much easier than debugging a half-converted file.

Our take

Use CSV when people will open the data in a spreadsheet or when you import into a tool that asks for it, and agree on UTF-8, the delimiter and the date format up front. Use JSON for anything that moves between programs, has nested data or needs real types. Do not expect a round trip to be lossless: CSV to JSON and back can change types, empty values and arrays. Keep the original export, convert a copy, and compare row counts and a few totals before you hand the result to anyone.

Anthony ParkerNetwork and systems engineer

Anthony has worked in IT for more than 17 years: office and field networks, servers, telephony, user support and security patching in international organisations. He writes about networking, security, developer tools and calculators.