CSV is a table written as text: one header line, then one line per row, values separated by commas. JSON is a tree of typed values: objects, lists, strings, numbers, booleans and null. CSV is smaller and opens in any spreadsheet; JSON keeps data types and nested fields. Use CSV for flat tables and JSON for anything with structure.
We measured the difference on real data. On 20 November 2026 we pulled 100 rows of market data, wrote the same rows as CSV, JSON and JSON Lines, and ran each file through Python's readers and pandas. The output below is from that run.
CSV vs JSON at a glance
| Question | CSV | JSON |
|---|---|---|
| Size of our 100 rows | 14,376 bytes | 30,053 bytes |
| After gzip | 6,331 bytes | 7,375 bytes |
| Shape | Rows and columns only | Any nesting of objects and lists |
| Data types | Every cell is text | String, number, boolean, null |
| Missing value | An empty cell | null |
| Column names | Once, in the header | In every record |
| Add a row to an existing file | Append one line | Rewrite the file, or use JSON Lines |
| Opens in | Spreadsheets, databases, pandas | Code, APIs, document databases, pandas |
The same rows as CSV and as JSON
The rows come from our crypto market data collector: the 100 largest coins by market cap at 18:16 UTC, with 13 columns kept (rank, id, symbol, name, price, market cap, volume, 24-hour change, circulating supply, maximum supply, all-time high, its date, and the update time). The first two lines of the CSV file:
rank,id,symbol,name,price,market_cap,volume_24h,change_24h_pct,circulating_supply,max_supply,ath,ath_date,last_updated
1,bitcoin,BTC,Bitcoin,58828,1183195111322,48110085084,-6.15,20114850,21000000,126080,2025-10-06T10:57:42.000Z,2026-11-20T18:15:55.000Z
The same row in JSON:
{"rank":1,"id":"bitcoin","symbol":"BTC","name":"Bitcoin","price":58828,"market_cap":1183195111322,
"volume_24h":48110085084,"change_24h_pct":-6.15,"circulating_supply":20114850,"max_supply":21000000,
"ath":126080,"ath_date":"2025-10-06T10:57:42.000Z","last_updated":"2026-11-20T18:15:55.000Z"}
The CSV line carries only values; the meaning of each position is in the header. The JSON record names every value and marks which ones are text (in quotes) and which are numbers.
CSV vs JSON file size: 14,376 bytes against 30,053
file bytes gzip
coins.csv 14,376 6,331
coins.json 30,053 7,375
coins.jsonl 30,052 7,374
coins.pretty.json 38,454 7,532
rows 100 columns 13 | key names repeated in JSON: 14500 bytes
- The JSON file was 2.1 times the size of the CSV file. Almost all of the difference is the column names: written with their quotes and colons in every one of the 100 records, they take 14,500 bytes. The CSV header spends 120 bytes on the same names, once.
- Gzip shrinks the gap to 16%. Repeated key names are exactly what compression removes: 7,375 bytes against 6,331. If the file travels over HTTP or sits in compressed storage, the size argument for CSV is much weaker than the raw numbers suggest.
- Indented JSON for people to read was 38,454 bytes, 2.7 times the CSV.
The ratio depends on the data. Short values with long column names, as here, favour CSV the most; rows with long text fields would bring the two files closer.
Data types: what each parser gives back
This is the difference that causes real bugs. We read both files back with Python's standard library and printed the Ethereum row, which has no maximum supply:
import csv, json
c0 = list(csv.DictReader(open("coins.csv", newline="", encoding="utf-8")))
j0 = json.load(open("coins.json", encoding="utf-8"))
rank csv str '2' json int 2
price csv str '1625.67' json float 1625.67
market_cap csv str '198688114236' json int 198688114236
max_supply csv str '' json NoneType None
ath_date csv str '2025-08-24T11:21:03.000Z' json str '2025-08-24T11:21:03.000Z'
Every CSV cell came back as a string. JSON returned an integer, a float and None. What that means in practice, from the same run, multiplying the first price by 2:
csv price * 2 -> '5882858828'
json price * 2 -> 117656
The CSV value "58828" was repeated, not doubled, because it is text. The missing value is the second trap: 49 of the 100 coins have no maximum supply. JSON says so with null; in CSV those 49 cells are empty strings, and an empty string cannot be told apart from a value that really is empty text. Neither format has a date type: ath_date is a string in both.
pandas guesses the types back when it reads CSV, and in this run it guessed the same as it got from JSON:
--- pandas dtypes (read_csv | read_json)
rank int64 | int64
price float64 | float64
market_cap int64 | int64
max_supply float64 | float64
ath_date str | str
shape (100, 13) (100, 13) | total market cap equal: True 2054290063883
Both frames had 100 rows and 13 columns and the same total. The guess is made from the values, though: max_supply became a float column because of the 49 empty cells, in both readers. Cleaning that up is covered in data wrangling in Python.
CSV vs JSON performance in Python
Each reader ran 300 times on the same 100 rows (the pandas readers 100 times); the figure is the median in milliseconds:
python 3.12.10 pandas 3.0.3 (median of 300 runs, ms)
csv.DictReader 0.172
json.loads 0.137
json lines 0.241
pandas.read_csv 0.585
pandas.read_json 1.954
| Reader | File | Median | Result |
|---|---|---|---|
json.loads | coins.json, 30,053 bytes | 0.137 ms | List of dicts, typed |
csv.DictReader | coins.csv, 14,376 bytes | 0.172 ms | List of dicts, all strings |
One json.loads per line | coins.jsonl | 0.241 ms | List of dicts, typed |
pandas.read_csv | coins.csv | 0.585 ms | DataFrame |
pandas.read_json | coins.json | 1.954 ms | DataFrame |
With the standard library, the JSON file parsed slightly faster even though it is twice the size, and it arrived typed. Into a pandas DataFrame, CSV loaded 3.3 times faster than JSON. So "which is faster" depends on where the data is going: plain Python objects favoured JSON here, a DataFrame favoured CSV. This is one run on one PC with 100 rows; on files of millions of rows, measure your own.
Appending rows, and where JSON Lines fits
A scraper that runs for hours adds rows as it goes. We appended one row to each file; its name contained a comma and quotes on purpose:
csv appended 157 bytes; last line: 101,example,EXM,"Example, ""quoted"" coin",58828,...
jsonl appended 312 bytes; lines now 101
json appended to the array file -> Extra data: line 1 column 30054 (char 30053)
csv read back name: Example, "quoted" coin | rows 101
- CSV: one more line, and the file is still valid. The
csvmodule put the name in quotes and doubled the inner quotes, and read it back intact. Write CSV with a library, never by joining strings with commas. - JSON array: a record written after the closing bracket made the file unreadable ("Extra data"). To add a row to a JSON array you load it, add the row and write the whole file again.
- JSON Lines (
.jsonl): one JSON object per line. It appends like CSV and keeps types and nesting like JSON; our file was 30,052 bytes, one byte less than the array. It is the usual format for scraper output, logs and LLM training files for that reason.
Nested data: where CSV stops
CSV has no way to put a list or an object in a cell. We wrote a record with a list and a nested object to CSV to see what happens:
name,keywords,links
parse5,"['html', 'parser', 'html5']",{'homepage': 'https://parse5.js.org'}
read back keywords: str "['html', 'parser', 'html5']"
Python wrote its own text form of the list into the cell, and reading it back gave a string, not a list. The working approach is to flatten on purpose before writing: pandas.json_normalize turned the nested object into a links.homepage column, and we joined the list with a separator:
json_normalize columns: ['name', 'keywords', 'links.homepage']
name,keywords,links.homepage
parse5,html|parser|html5,https://parse5.js.org
That works for one level. A record with a list of objects, such as a product with several offers, needs either one row per offer or a second file, and at that point JSON is the simpler format.
CSV or JSON: which to use
| Your case | Use | Why, from the run above |
|---|---|---|
| A flat table for a spreadsheet, a database import or pandas | CSV | Half the bytes, and the fastest DataFrame load (0.585 ms) |
| Records with lists or nested objects | JSON | CSV turned the list into text |
| Types and missing values must survive | JSON | Numbers stayed numbers, null stayed null |
| Output of a long scraping job, logs | JSON Lines | Appends one line at a time, keeps types |
| An API response | JSON | It is what clients expect; see parsing JSON in Python |
You can also keep both: collect as JSON, which loses nothing, and export a CSV view when someone needs a spreadsheet. Our collectors work that way: a run returns JSON, and the same rows can be fetched as CSV text. For HTML tables that should end up as CSV, see scraping a table from a website with Python; for the other common comparison, JSON vs XML; for pages that are not data yet, the Web Scraping API returns them as structured JSON.


