Guide

Parquet vs JSON for sports backtesting: a local benchmark

Short answer: for backtesting, convert API responses to Parquet. On 600,000 synthetic play rows, Parquet was about 9 MB against 182 MB for JSON, and a full read took 0.02 seconds against 1.29. A two-column filtered read was near zero. CSV read just as fast but lost the string game ids.

The numbers below come from a script run on this machine, an Apple M4 Max with 14 cores, Python 3.12.15, pandas 3.1.2 and pyarrow 26.0.1. They describe synthetic rows with a realistic shape, and the caveats come before the conclusions.

Why storage format matters for a backtest

A backtest reads the same data many times. You refit a model on each walk-forward fold, rerun a feature after a bug fix and sweep parameters, and each pass starts with a read. JSON is what the API returns, which makes it the natural thing to save, but it is a text format with every key repeated on every row. A play-by-play table with a million rows repeats its field names a million times.

Parquet is a columnar binary format. It stores each column together, compresses it with the column's own type in mind, and lets a reader skip columns and row groups it does not need. For tabular sports data, with repeated team codes, event types and ids, those properties usually pay off. Whether they pay off by a little or a lot is a measurement, so we measured.

The benchmark

The rows imitate a get_plays response. Each of 600,000 rows, about one NBA regular season of plays, has 17 columns: a string game id, sequence, period, clock seconds, a team code from 30 values, an event type from 45, a text description, a made flag, x and y court coordinates, distance, expected points, points, a string player id, two running scores and a win probability. Values are random, drawn with a fixed seed.

import numpy as np, pandas as pd

N = 600_000
rng = np.random.default_rng(42)
teams = [f"T{i:02d}" for i in range(30)]
types = [f"Shot type {i}" for i in range(45)]
players = [f"Player Name {i}" for i in range(450)]
pid = rng.integers(0, 450, N)
df = pd.DataFrame({
    "game_id": (401_900_000 + rng.integers(0, 1230, N)).astype(str),
    "seq": rng.integers(0, 520, N), "period": rng.integers(1, 5, N),
    "clock_seconds": rng.integers(0, 721, N),
    "team": rng.choice(teams, N), "type": rng.choice(types, N),
    "text": [f"{players[i]} makes {d}-foot jump shot" for i, d in zip(pid, rng.integers(1, 30, N))],
    "made": rng.random(N) < 0.46, "x": rng.integers(0, 51, N), "y": rng.integers(0, 48, N),
    "distance_ft": rng.random(N).round(1) * 30, "expected_points": rng.random(N).round(3),
    "points": rng.integers(0, 4, N), "player_id": (4_000_000 + pid).astype(str),
    "home_score": rng.integers(0, 130, N), "away_score": rng.integers(0, 130, N),
    "home_win_prob": rng.random(N).round(3),
})
df.to_json("p.json", orient="records")                      # one big array
df.to_json("p.ndjson", orient="records", lines=True)        # one object per line
df.to_csv("p.csv", index=False)
df.to_parquet("p_snappy.parquet", compression="snappy")
df.to_parquet("p_zstd.parquet", compression="zstd")

Each read was timed three times and the median is shown. The files were already in the operating system's cache, so these are warm reads. "2 cols + filter" reads two columns and keeps one team's rows, 20,101 of 600,000.

FormatSize (MB)Write (s)Read all (s)2 cols + filter (s)
JSON array182.20.641.291.29
NDJSON182.20.971.601.61
CSV71.81.040.020.04
Parquet, snappy9.30.130.020.00
Parquet, zstd9.10.130.010.00

Parquet was about 20 times smaller than JSON and 8 times smaller than CSV. Reading all of it back took 1.29 seconds as JSON and 0.02 as Parquet. The filtered two-column read cost JSON the same 1.29 seconds, because the whole file has to be parsed to get at any of it, while Parquet needed under 5 milliseconds.

What the table does not say

Read the results with these in mind.

  • The data is random and low-cardinality. Thirty team codes, 45 event types and 450 player names compress far better than real data may. Parquet's 20 times smaller figure is likely close to a best case. A real game's shape is not far off, as shown below, but check on your own files.
  • CSV looks too good. A 72 MB CSV parsed in 0.02 seconds which is likely down to pandas 3.1.2 and a fast multithreaded reader on 14 cores. We did not isolate the cause. On an older pandas or a laptop with fewer cores, expect CSV to be much slower. We did not test that.
  • Types did not survive CSV or NDJSON. The string game_id came back as an int64 from both, which silently drops leading zeros on ids that have them. Parquet round-tripped every dtype exactly.
  • Warm cache. A cold read from a slow disk would be dominated by bytes read, which favors Parquet more.
  • One machine, one run of three. There are no error bars.

Doing it with real API data

A real game is a useful check on the size claim. The get_plays response for one NBA game, game 401909453, was 485 plays. Saved as JSON it was 191,620 bytes, about 395 per play. As Parquet with zstd it was 21,091 bytes, 9 times smaller, on one game with a lot of unique text. Each play also has a nested shot object, which pyarrow keeps as a struct column instead of forcing you to flatten it.

import json, os, urllib.request
import pyarrow as pa, pyarrow.parquet as pq

KEY = os.environ["DUNKAPI_API_KEY"]
def post(tool, body):
    req = urllib.request.Request("https://mcp.dunkapi.com/v1/" + tool, data=json.dumps(body).encode(),
          headers={"Content-Type": "application/json", "x-api-key": KEY})
    with urllib.request.urlopen(req, timeout=60) as r:
        return json.load(r)["data"]

plays, offset = [], 0
while offset is not None:                                  # follow next_offset to the end
    page = post("get_plays", {"game_id": "401909453", "limit": 500, "offset": offset})
    plays += page["plays"]; offset = page.get("next_offset")

table = pa.Table.from_pylist(plays)                        # nested "shot" object becomes a struct
pq.write_table(table, "game.parquet", compression="zstd")
cols = pq.read_table("game.parquet", columns=["seq", "clock_seconds", "home_win_prob"])
print(cols.num_rows, cols.slice(0, 1).to_pylist())
# 485 [{'seq': 0, 'clock_seconds': 720, 'home_win_prob': 0.616}]

A reasonable workflow for a backtest is a landing area of raw JSON, one file per call, never edited, plus a Parquet dataset built from it. Partition the Parquet by season, so a fold that trains on three seasons reads three directories. Rebuild the Parquet from the raw files when the schema changes. This keeps the exact response you received, which matters because records are overwritten when a source corrects them and no revision history is kept on the API side.

Why the filtered read is so cheap

Parquet files are split into row groups, and each column inside a group is stored with its own minimum and maximum. When you pass filters=[("team", "==", "T07")], pyarrow compares the filter with those statistics and skips groups that cannot match. When you pass columns=[...], it never reads the other columns' bytes at all. In our random data every team appears in every row group, so the filter could not skip whole groups, and the speed came from reading two narrow columns out of 17. Real data sorted by season or team can skip much more. If your backtest filters on a column, sort the data by it before writing.

Choosing, in practice

  • Under a few thousand rows: use whatever is convenient. JSON or CSV is fine.
  • A season of play-by-play or more: use Parquet. The read time and the size both matter once you refit often.
  • Many small files, one per game: combine them. Thousands of tiny Parquet files read slowly. Aim for files of tens to hundreds of megabytes.
  • Need to read it from several languages: Parquet has readers in Python, R, Rust, Java and others, and keeps types.
  • Need to inspect by eye: keep a CSV or JSON sample next to it.

Limits

  • Synthetic rows. Only the 485-play game is real, and it shows a smaller ratio than the synthetic run.
  • Warm cache, one machine. Numbers will shift on other hardware, a network drive or an older pandas.
  • No query engine tested. We read with pandas and pyarrow. DuckDB and others read Parquet too, and we did not time them.
  • No compression tuning. Snappy and zstd at default levels, no dictionary or row-group settings changed.
  • Terms apply. You may store the data and build models from it. You may not redistribute it as a dataset or feed.

Get a free key Or download whole seasons as Parquet

Checked against the live API on 2026-12-06. Questions: hello@sportsdatahq.com.