import streamlit as st import openpyxl import pandas as pd import json st.set_page_config('JSON REPLACEMENT',layout="wide") st.markdown(""" """, unsafe_allow_html=True) #Title of the page with CSS st.markdown(""" """, unsafe_allow_html=True) st.markdown('

JSON FILE REPLACEMENT

', unsafe_allow_html=True) with st.container(): col1, col2= st.columns(2) with col1: data_file=st.file_uploader("Upload Excel file",type=['xlsx']) if data_file: with col2: wb = openpyxl.load_workbook(data_file) sheet_selector = st.multiselect("Select sheet:",wb.sheetnames) if data_file: if len(sheet_selector)==1: df1 = pd.read_excel(data_file,sheet_selector[0]) st.markdown('

COLUMN MAPPING

', unsafe_allow_html=True) st.dataframe(df1) col1,col2=st.columns(2) with col1: df1_col=st.multiselect('Replaced From:',df1.columns) existing=df1.iloc[:,0] with col2: df2_col=st.multiselect('Replaced To:',df1.columns) replaced=df1.iloc[:,1] json_file=st.file_uploader("Upload JSON file",type=['json']) if json_file is not None: jfile=json_file.read() #Read as string jfile=jfile.decode('utf8') #byte to string for i in range(len(existing)): #Traverse through the list jfile = jfile.replace(existing[i], replaced[i]) new_name=st.text_input("Provide Name for the file") f_name=new_name+".json" st.download_button( label="Download JSON", file_name=f_name, mime="application/json", data=jfile )