File size: 621 Bytes
01f199c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | import json
# Read an jsonl file and convert it into a python list of dictionaries.
def read_jsonl(filename):
"""Reads a jsonl file and yields each line as a dictionary"""
lines = []
with open(filename, "r", encoding="utf-8") as file:
for line in file:
lines.append(json.loads(line))
return lines
# Write a python list of dictionaries into a jsonl file
def write_jsonl(filename, lines):
"""Writes a python list of dictionaries into a jsonl file"""
with open(filename, "w", encoding="utf-8") as file:
for line in lines:
file.write(json.dumps(line) + "\n")
|