Skip to content

Commit 0ab31c3

Browse files
committed
fix: add json integration
1 parent 28c9dce commit 0ab31c3

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

scrapegraphai/graphs/json_scraper_graph.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def _create_graph(self) -> BaseGraph:
5454
"""
5555

5656
fetch_node = FetchNode(
57-
input="json_dir",
57+
input="json",
5858
output=["doc"],
5959
)
6060
parse_node = ParseNode(
@@ -106,4 +106,4 @@ def run(self) -> str:
106106
inputs = {"user_prompt": self.prompt, self.input_key: self.source}
107107
self.final_state, self.execution_info = self.graph.execute(inputs)
108108

109-
return self.final_state.get("answer", "No answer found.")
109+
return self.final_state.get("answer", "No answer found.")

scrapegraphai/nodes/fetch_node.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
FetchNode Module
33
"""
44
import pandas as pd
5+
import json
56
from typing import List, Optional
67
from langchain_community.document_loaders import AsyncChromiumLoader
78
from langchain_core.documents import Document
@@ -75,8 +76,13 @@ def execute(self, state):
7576
compressed_document = loader.load()
7677

7778
elif self.input == "csv":
78-
compressed_document = [Document(page_content=pd.read_csv(source), metadata={
79-
"source": "xml"
79+
compressed_document = [Document(page_content=str(pd.read_csv(source)), metadata={
80+
"source": "csv"
81+
})]
82+
elif self.input == "json":
83+
f = open(source)
84+
compressed_document = [Document(page_content=str(json.load(f)), metadata={
85+
"source": "json"
8086
})]
8187
elif self.input == "xml":
8288
with open(source, 'r', encoding='utf-8') as f:

0 commit comments

Comments
 (0)