Comparison_json / src /streamlit_app.py
Terence9's picture
Update src/streamlit_app.py
469cee7 verified
import json
import streamlit as st
#Function to extract all values from a nested JSON
def extract_values(data):
if isinstance(data, dict):
for value in data.values():
yield from extract_values(value)
elif isinstance(data, list):
for item in data:
yield from extract_values(item)
else:
yield data
#Function to comparison of two JSON
def compare_json(json1, json2):
value1 = set(extract_values(json1))
value2 = set(extract_values(json2))
return list(value1.intersection(value2))
#streamlit UI
st.title("Json file Comparison File")
st.write("Upload Two JSON files to find similar values.")
file1 = st.file_uploader("Upload First JSON File", type=["json"])
file2 = st.file_uploader("Upload Second JSON File", type=["json"])
if file1 and file2:
json1 = json.load(file1)
json2 = json.load(file2)
matches = compare_json(json1, json2)
if matches:
st.subheader("Similar values found")
st.table(matches)
else:
st.warning("No similar value founder")