File size: 2,247 Bytes
b181f80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import streamlit as st
import openpyxl
import pandas as pd
import json 

st.set_page_config('JSON REPLACEMENT',layout="wide")
st.markdown("""
        <style>
               .css-18e3th9 {
                    padding-top: 0rem;
                    padding-bottom: 10rem;
                    padding-left: 5rem;
                    padding-right: 5rem;
                }
               .css-1d391kg {
                    padding-top: 3.5rem;
                    padding-right: 1rem;
                    padding-bottom: 3.5rem;
                    padding-left: 1rem;
                }
        </style>
        """, unsafe_allow_html=True)

#Title of the page with CSS

st.markdown(""" <style> .font {font-size:40px ; font-family: 'Verdana'; color: 	#000000;} .font1 {font-size:20px ; font-family: 'Verdana'; color: 	red;} </style> """, unsafe_allow_html=True)
st.markdown('<p class="font">JSON FILE REPLACEMENT</p>', 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('<p class="font1">COLUMN MAPPING</p>', 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
    )