Spaces:
Sleeping
Sleeping
File size: 1,078 Bytes
f2f99b6 92476e9 f2f99b6 2e54534 f2f99b6 63003f5 f2f99b6 469cee7 f2f99b6 33a4ece f2f99b6 f731bd4 f2f99b6 | 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 | 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")
|