Update app.py
Browse files
app.py
CHANGED
|
@@ -19,18 +19,20 @@ minify = gr.Interface(
|
|
| 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 |
-
|
| 30 |
-
minified_rows = []
|
| 31 |
for key, value in json_content.items():
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
| 34 |
except json.JSONDecodeError:
|
| 35 |
return "Invalid JSON input. Please provide a valid JSON."
|
| 36 |
|
|
|
|
| 19 |
"text"
|
| 20 |
)
|
| 21 |
|
| 22 |
+
# Function to minify JSON with each key-value pair on a new line without extra indentation
|
| 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 |
+
minified_rows = ["{"]
|
|
|
|
| 30 |
for key, value in json_content.items():
|
| 31 |
+
# Serialize value to JSON and append to list
|
| 32 |
+
serialized_value = json.dumps(value, separators=(',', ':'))
|
| 33 |
+
minified_rows.append(f' "{key}": {serialized_value}')
|
| 34 |
+
minified_rows.append("}")
|
| 35 |
+
return "\n".join(minified_rows)
|
| 36 |
except json.JSONDecodeError:
|
| 37 |
return "Invalid JSON input. Please provide a valid JSON."
|
| 38 |
|