Below is a compact “cheat-sheet” you can drop straight into a Colab notebook.
It covers the two most common scenarios:
• Your .jsonl file is already in the Colab working directory (e.g. ./data/my_file.jsonl)
• Your file lives in Google Drive ➜ you first mount Drive, then read.
Feel free to delete the parts you don’t need.
# ───────────────────────────────────────
# 1) If the file is already inside Colab
# ───────────────────────────────────────
import pandas as pd
from pathlib import Path
import json
# Path to the .jsonl file
jsonl_path = Path("data") / "my_file.jsonl" # adjust as needed
# ----- 1-A. Quick & convenient: pandas -----
df = pd.read_json(jsonl_path, lines=True) # 'lines=True' is the crucial bit
display(df.head()) # peek at the first rows
print(df.shape) # (#rows, #cols)
# ----- 1-B. Full control: line-by-line -----
records = []
with open(jsonl_path, "r", encoding="utf-8") as f:
for line in f:
records.append(json.loads(line))
# Now 'records' is a list of dicts
# You can still turn it into a DataFrame if you like
df2 = pd.DataFrame(records)
# ───────────────────────────────────────────────
# 2) If the file is in your Google Drive
# ───────────────────────────────────────────────
from google.colab import drive
import pandas as pd
import json, pathlib
# Mount Drive (you'll be asked to grant permission once)
drive.mount('/content/drive')
# Build the path to your file inside Drive
drive_root = pathlib.Path("/content/drive/My Drive") # 'My Drive' is the default
jsonl_path = drive_root / "my_datasets" / "my_file.jsonl"
# -- Same options as above --
# 2-A. Using pandas
df = pd.read_json(jsonl_path, lines=True)
display(df.head())
# 2-B. Manual line-by-line parsing
records = [json.loads(line) for line in open(jsonl_path, "r", encoding="utf-8")]
Tips & gotchas
• jsonl (JSON Lines) = one valid JSON object per line. lines=True tells pandas to treat each line separately.
• For very large files you can read in chunks with pd.read_json(..., lines=True, chunksize=10_000) or stream manually.
• If your file uses a different encoding (rare) specify encoding='xyz' in open() or read_json().
That’s it—replace the path strings with yours and run! 🚀