JSON vs CSV: Which Format Should You Use?
JSON and CSV both carry data as text, and both are easy to produce, so it is tempting to treat them as interchangeable. They are not. Each fits a different shape of data and a different reader. Choosing the wrong one is the usual reason for conversion headaches later.
The short answer
Use CSV for flat tables that people will open in a spreadsheet or load into a database. Use JSON for data that has structure, such as nested objects and lists, and for anything exchanged between programs and APIs.
Side by side
| CSV | JSON | |
|---|---|---|
| Shape | Flat rows and columns | Nested objects and arrays |
| Data types | None. Everything is text, and the reader guesses | Strings, numbers, true, false, null, objects and arrays |
| Column names | One optional header row | Every value has its own key |
| Missing values | An empty cell, which is ambiguous | Leave the key out, or write null |
| Size for the same table | Smaller, because keys are written once | Larger, because keys repeat in every record |
| Opens in Excel | Yes, with the caveats below | Not directly; needs import or conversion |
| Used by APIs | Rarely | Very commonly |
| Human editing | Easy in a spreadsheet | Easy in a text editor if small, hard if large |
| Specification | Informal; RFC 4180 describes common practice | Strict; RFC 8259 |
When CSV is the better choice
- The data is naturally a table: orders, contacts, transactions, sensor readings.
- The audience uses Excel, Google Sheets or a BI tool.
- You are loading rows into a database table or a data warehouse.
- File size matters and every record has the same fields.
The weakness is that CSV carries no types. A reader sees 00123 and may turn it into 123, or sees a long ID and rounds it, or sees MAR1 and shows a date. That is why spreadsheets damage IDs and codes, as explained in why Excel changes long numbers in CSV. Encoding and delimiter differences cause the other common problems, covered in garbled characters and one-column files in Excel.
When JSON is the better choice
- Records contain lists or objects, such as an order with several items.
- The data moves between systems, for example an API response or a webhook.
- You need real types: a number that must stay a number, a true or false value, a null.
- Records have different fields from one another.
The weakness is that JSON is not a table. Opening it in a spreadsheet means flattening it first, and flattening needs decisions about arrays, covered in how to flatten nested JSON into CSV.
What about YAML and XML?
YAML is mostly used for configuration files, such as Kubernetes manifests and CI pipelines, where people edit the file by hand. XML is common in older enterprise systems, feeds and some file formats. JSON is the usual choice for new APIs. You can convert JSON to YAML or XML when a system asks for one of them.
A simple way to decide
- Look at the shape. If every record has the same flat fields, CSV works. If records contain lists or nested objects, use JSON.
- Look at the reader. A person with a spreadsheet wants CSV or Excel. A program wants JSON.
- Look at the types. If IDs, codes or exact numbers matter, prefer JSON or an Excel file, which can hold them as text.
Converting between them
The conversion is not lossless in either direction. Going from JSON to CSV flattens structure, and going from CSV to JSON has to guess types. Use the JSON to CSV converter and the CSV to JSON converter, which keep long IDs and leading zeros as text and show a preview so you can check the result. Both run in your browser, so your data is not uploaded.