File size: 698 Bytes
d2a63cc
 
 
 
 
 
e4316f1
d2a63cc
 
 
 
 
0b9d8c7
d2a63cc
 
 
0b9d8c7
d2a63cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import json
from typing import Any, Dict, List

from graphgen.bases.base_reader import BaseReader


class JSONReader(BaseReader):
    def read(self, file_path: str) -> List[Dict[str, Any]]:
        with open(file_path, "r", encoding="utf-8") as f:
            data = json.load(f)
            if isinstance(data, list):
                for doc in data:
                    if doc.get("type") == "text" and self.text_column not in doc:
                        raise ValueError(
                            f"Missing '{self.text_column}' in document: {doc}"
                        )
                return self.filter(data)
            raise ValueError("JSON file must contain a list of documents.")