File size: 931 Bytes
f58978f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import json

def read_jsonl_file(file_path):
    """
    Reads a .jsonl file and returns a list of Python dictionaries,
    where each dictionary represents a JSON object from a line in the file.
    """
    data = []
    try:
        with open(file_path, 'r', encoding='utf-8') as f:
            for line in f:
                # Strip whitespace and check if the line is not empty
                stripped_line = line.strip()
                if stripped_line:
                    try:
                        json_object = json.loads(stripped_line)
                        data.append(json_object)
                    except json.JSONDecodeError as e:
                        print(f"Error decoding JSON on line: {stripped_line}. Error: {e}")
    except FileNotFoundError:
        print(f"Error: The file '{file_path}' was not found.")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")
    return data