Read a JSONL File
Quick Answer
Read JSONL one line at a time. Each line should be parsed as its own JSON value, which makes the format useful for logs, exports, and large datasets that should not be loaded into memory all at once.
For a no-code option, use the JSONL viewer. For code examples, parse each line, skip blank lines, and report line numbers when parsing fails.
Python Example
import json
with open("data.jsonl", "r", encoding="utf-8") as file:
for line_number, line in enumerate(file, start=1):
if not line.strip():
continue
record = json.loads(line)
print(line_number, record)
JavaScript Example
const lines = input.split(/\r?\n/).filter(Boolean);
const records = lines.map((line) => JSON.parse(line));
Next Steps
- JSONL Parser Guide for more languages and performance patterns.
- JSONL Validator to debug invalid records.
- JSON Lines Format Specification for formal rules.