Stream newline-delimited JSON
Read JSONL files one record at a time without loading the full file.
Original Pearto instructional example. Test it in your own environment and adapt it to your requirements.
import json
from pathlib import Path
def read_jsonl(path):
with Path(path).open(encoding='utf-8') as file:
for line in file:
if line.strip():
yield json.loads(line)
# for record in read_jsonl('events.jsonl'):
# print(record)