Code Implementation
Python
import json
def read_jsonl(file_path):
with open(file_path, "r", encoding="utf-8") as f:
for line in f:
yield json.loads(line)
# Usage
for record in read_jsonl("data.jsonl"):
print(record)
Read JSONL (JSON Lines) files line by line in Python, suitable for processing large-scale datasets.
#json#jsonl
Snippet Description
- Each line in a JSONL file is an independent JSON object
- Use
yield
to implement a line-by-line generator to avoid loading all data at once - Often used in log and big data scenarios
Recommended Snippets
Python Remove Duplicates from List of Dicts
Remove duplicates from a list of dictionaries based on a specific key in the dictionaries.
Python
#dict+1
6
0
Python Read Nested JSON File Example
How to read JSON files with nested structures in Python and safely access deep-level fields.
Python
#json+1
8
0
Python: Write Dict to CSV with Headers
Write a list of dictionaries to a CSV file and automatically generate headers.
Python
#dict+1
6
0
Comments
Loading...