Update app.py
Browse files
app.py
CHANGED
@@ -19,15 +19,18 @@ minify = gr.Interface(
|
|
19 |
"text"
|
20 |
)
|
21 |
|
22 |
-
# Function to minify JSON with each key on a new line
|
23 |
def minify_json_to_row(input_text, uploaded_file):
|
24 |
try:
|
25 |
if uploaded_file is not None:
|
26 |
input_text = uploaded_file["data"].decode("utf-8")
|
27 |
|
28 |
json_content = json.loads(input_text)
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
31 |
except json.JSONDecodeError:
|
32 |
return "Invalid JSON input. Please provide a valid JSON."
|
33 |
|
|
|
19 |
"text"
|
20 |
)
|
21 |
|
22 |
+
# Function to minify JSON with each key-value pair on a new line
|
23 |
def minify_json_to_row(input_text, uploaded_file):
|
24 |
try:
|
25 |
if uploaded_file is not None:
|
26 |
input_text = uploaded_file["data"].decode("utf-8")
|
27 |
|
28 |
json_content = json.loads(input_text)
|
29 |
+
# Iterate through the items and create a string representation
|
30 |
+
minified_rows = []
|
31 |
+
for key, value in json_content.items():
|
32 |
+
minified_rows.append(f'"{key}":{json.dumps(value, separators=(",", ":"))}')
|
33 |
+
return "{\n" + ",\n".join(minified_rows) + "\n}"
|
34 |
except json.JSONDecodeError:
|
35 |
return "Invalid JSON input. Please provide a valid JSON."
|
36 |
|