-
Notifications
You must be signed in to change notification settings - Fork 9
/
json_editor.py
32 lines (26 loc) · 986 Bytes
/
json_editor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import streamlit as st
import json
# Function to load JSON
def load_json(uploaded_file):
data = json.load(uploaded_file)
return data
# Function to save JSON
def save_json(file, data):
with open(file, 'w') as f:
json.dump(data, f, indent=4)
# Upload the JSON file
uploaded_file = st.file_uploader("Choose a JSON file", type='json')
if uploaded_file is not None:
data = load_json(uploaded_file)
# Display JSON in a text area (as a string for editing)
json_str = st.text_area("JSON Input", json.dumps(data, indent=4))
edited_data = json.loads(json_str)
# Input for the file path
file_path = st.text_input("Enter the file path where you want to save the edited file")
# Button to save the changes
if st.button('Save JSON'):
if file_path:
save_json(file_path.strip(), edited_data)
st.success('File saved')
else:
st.error('Please enter a file path')