File size: 805 Bytes
65dac95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4e4ea7e
 
 
 
 
 
 
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
import streamlit as st
import pandas as pd
import json

# Title of the app
st.title('Gen AI Jam JSON Visualizer')

# File uploader widget
uploaded_file = st.file_uploader("Choose a JSON file", type=['json'])
if uploaded_file is not None:
    # Reading the file
    file_data = json.load(uploaded_file)

    # If the JSON is deeply nested, you may need to normalize it to create a flat table
    if isinstance(file_data, list):  # Assuming the JSON is an array of records
        df = pd.json_normalize(file_data)
    else:
        df = pd.json_normalize(file_data, max_level=1)

    # Display the dataframe as a table
    st.write(df)

    st.download_button(
        label="Download CSV",
        data=df.to_csv(index=False).encode('utf-8'),
        file_name='table.csv',
        mime='text/csv',
    )