han-byeol commited on
Commit
ccc2ac1
ยท
1 Parent(s): 04e3866

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -1
app.py CHANGED
@@ -46,13 +46,25 @@ def get_csv_file(csv_docs):
46
  csv_loader = CSVLoader(temp_filepath)
47
  csv_doc = csv_loader.load()
48
  return csv_doc
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
  def get_json_file(json_docs):
51
  temp_dir = tempfile.TemporaryDirectory()
52
  temp_filepath = os.path.join(temp_dir.name, json_docs.name)
53
  with open(temp_filepath, "wb") as f:
54
  f.write(json_docs.getvalue())
55
- json_loader = JSONLoader(temp_filepath)
56
  json_doc = json_loader.load()
57
  return json_doc
58
 
 
46
  csv_loader = CSVLoader(temp_filepath)
47
  csv_doc = csv_loader.load()
48
  return csv_doc
49
+
50
+ class JSONLoader:
51
+ def __init__(self, file_path, jq_schema):
52
+ self.file_path = file_path
53
+ self.jq_schema = jq_schema
54
+
55
+ def load(self):
56
+ with open(self.file_path, 'r') as json_file:
57
+ data = json.load(json_file)
58
+ # ์—ฌ๊ธฐ์„œ jq_schema๋ฅผ ํ™œ์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•  ๊ฒƒ์œผ๋กœ ๊ฐ€์ •ํ•ฉ๋‹ˆ๋‹ค.
59
+ processed_data = process_with_schema(data, self.jq_schema)
60
+ return processed_data
61
 
62
  def get_json_file(json_docs):
63
  temp_dir = tempfile.TemporaryDirectory()
64
  temp_filepath = os.path.join(temp_dir.name, json_docs.name)
65
  with open(temp_filepath, "wb") as f:
66
  f.write(json_docs.getvalue())
67
+ json_loader = JSONLoader(temp_filepath, jq_schema={})
68
  json_doc = json_loader.load()
69
  return json_doc
70