Documentation Python quickstart Blog Free tools Enterprise solutions hello@quanticdata.ioLog in

CSV vs JSON: file size, data types and speed on the same 100 real rows

The same 100 real rows of market data written as CSV and as JSON on 20 November 2026: 14,376 bytes as CSV and 30,053 bytes as JSON, because JSON repeats the 13 column names in every row; the card shows what the Python readers returned for one cell: the text 58828 from CSV and the number 58828 from JSON, and that an empty CSV cell stands for null.
The same 100 real rows of market data written as CSV and as JSON on 20 November 2026: 14,376 bytes as CSV and 30,053 bytes as JSON, because JSON repeats the 13 column names in every row; the card shows what the Python readers returned for one cell: the text 58828 from CSV and the number 58828 from JSON, and that an empty CSV cell stands for null.

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

QuestionCSVJSON
Size of our 100 rows14,376 bytes30,053 bytes
After gzip6,331 bytes7,375 bytes
ShapeRows and columns onlyAny nesting of objects and lists
Data typesEvery cell is textString, number, boolean, null
Missing valueAn empty cellnull
Column namesOnce, in the headerIn every record
Add a row to an existing fileAppend one lineRewrite the file, or use JSON Lines
Opens inSpreadsheets, databases, pandasCode, 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
ReaderFileMedianResult
json.loadscoins.json, 30,053 bytes0.137 msList of dicts, typed
csv.DictReadercoins.csv, 14,376 bytes0.172 msList of dicts, all strings
One json.loads per linecoins.jsonl0.241 msList of dicts, typed
pandas.read_csvcoins.csv0.585 msDataFrame
pandas.read_jsoncoins.json1.954 msDataFrame

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 csv module 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 caseUseWhy, from the run above
A flat table for a spreadsheet, a database import or pandasCSVHalf the bytes, and the fastest DataFrame load (0.585 ms)
Records with lists or nested objectsJSONCSV turned the list into text
Types and missing values must surviveJSONNumbers stayed numbers, null stayed null
Output of a long scraping job, logsJSON LinesAppends one line at a time, keeps types
An API responseJSONIt 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.

Sources & further reading

FAQ

Quick answers on csv vs json.

Something else? Ask us

What is the difference between CSV and JSON?

CSV stores a flat table as text: a header line and one line per row, every cell a string. JSON stores a tree of typed values: objects, lists, strings, numbers, booleans and null. CSV is smaller; JSON keeps types and nested fields.

Is CSV smaller than JSON?

For our 100 rows of 13 columns, yes: 14,376 bytes of CSV against 30,053 bytes of JSON, because JSON repeats the column names in every record. After gzip the files were 6,331 and 7,375 bytes, a 16% difference.

Is CSV faster than JSON?

It depended on the reader in our run. With Python's standard library, json.loads took 0.137 ms and csv.DictReader 0.172 ms. Loading into pandas, read_csv took 0.585 ms and read_json 1.954 ms.

What is JSON Lines (JSONL)?

A file with one JSON object per line. A new record is appended as a new line, as in CSV, and each record keeps its types and nesting, as in JSON. In our test the JSON Lines file was 30,052 bytes and stayed valid after an append.

Does CSV have data types?

No. Python's csv module returned every cell as a string in our test, including the price "58828" and the empty cells of the 49 rows without a maximum supply. pandas infers types from the values when it reads the file.

Can CSV store nested data?

Not directly. A list written to a CSV cell came back as the string "['html', 'parser', 'html5']" in our test. Flatten first, for example with pandas.json_normalize, or keep the data in JSON.

Collect once as JSON, export as CSV when you need a table

Collectors return typed JSON records from public pages, with a CSV export of the same rows.

Related reading