Skip to content

Commit 41d390d

Browse files
feat: support JSON and JSONL file uploads (#1012)
1 parent daaa76a commit 41d390d

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

frontend/src2/data_source/UploadCSVFileDialog.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ function resetFile() {
9393
<Dialog
9494
v-model="show"
9595
:options="{
96-
title: csvData.tablename ? __('Import Table') : __('Upload CSV/Excel File'),
96+
title: csvData.tablename ? __('Import Table') : __('Upload CSV/Excel/JSON File'),
9797
size: fileUploaded ? '4xl' : '',
9898
}"
9999
>
100100
<template #body-content>
101101
<FileUploader
102102
v-if="!fileUploaded"
103103
:uploadArgs="{ private: true }"
104-
:file-types="['.csv', '.xlsx']"
104+
:file-types="['.csv', '.xlsx', '.json', '.jsonl']"
105105
@success="uploadFile"
106106
>
107107
<template #default="{ progress, uploading, openFileSelector }">
@@ -116,7 +116,7 @@ function resetFile() {
116116
/>
117117
<div class="text-center">
118118
<p v-if="!uploading" class="text-sm font-medium text-gray-800">
119-
Select a CSV or Excel file to upload
119+
Select a CSV, Excel, or JSON file to upload
120120
</p>
121121
<p v-if="!uploading" class="mt-1 text-xs text-gray-600">
122122
or drag and drop it here

frontend/src2/query/components/QueryBuilderTable.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ function addNewColumn() {
7979
:enable-column-rename="true"
8080
:enable-alerts="true"
8181
:enable-new-column="true"
82+
:enable-drill-down="true"
8283
>
8384
<template #header-prefix="{ column }">
8485
<ColumnTypeChange

insights/api/__init__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ def get_csv_file(filename: str):
9191
extension = parts[-1] if parts else ""
9292
extension = extension.lstrip(".")
9393

94-
if not extension or extension not in ["csv", "xlsx"]:
94+
if not extension or extension not in ["csv", "xlsx", "json", "jsonl"]:
9595
frappe.throw(
96-
f"Only CSV and XLSX files are supported. Detected extension: '{extension}' from filename: '{file_name}'"
96+
f"Only CSV, XLSX, JSON, and JSONL files are supported. Detected extension: '{extension}' from filename: '{file_name}'"
9797
)
9898
return file, extension
9999

@@ -128,6 +128,8 @@ def get_file_data(filename: str):
128128
try:
129129
if ext in ["xlsx"]:
130130
table = db.read_xlsx(file_path)
131+
elif ext in ["json", "jsonl"]:
132+
table = db.read_json(file_path)
131133
else:
132134
table = db.read_csv(file_path, table_name=file_name)
133135

@@ -162,6 +164,8 @@ def import_csv_data(filename: str, tablename: str = ""):
162164
try:
163165
if ext in ["xlsx"]:
164166
table = db.read_xlsx(file_path)
167+
elif ext in ["json", "jsonl"]:
168+
table = db.read_json(file_path)
165169
else:
166170
table = db.read_csv(file_path, table_name=table_name)
167171
db.create_table(table_name, table, overwrite=True)
@@ -171,6 +175,10 @@ def import_csv_data(filename: str, tablename: str = ""):
171175
frappe.throw(
172176
"Failed to read Excel data from uploaded file. Please ensure the file is a valid Excel format and try again."
173177
)
178+
elif ext in ["json", "jsonl"]:
179+
frappe.throw(
180+
"Failed to read JSON data from uploaded file. Please ensure the file is a valid JSON or JSONL format and try again."
181+
)
174182
else:
175183
frappe.throw("Failed to read CSV data from uploaded file. Please try again.")
176184
finally:

0 commit comments

Comments
 (0)