web service to transform json from one shape to another using templates
To upload files, please first save the app
import streamlit as st
import pandas as pd
import json
st.title('JSON Transformer')
# Function to transform JSON using a template
def transform_json(data, template):
transformed_data = []
for entry in data:
transformed_entry = {key: entry.get(value) for key, value in template.items()}
transformed_data.append(transformed_entry)
return transformed_data
# Input JSON
input_json = st.text_area('Input JSON', height=300)
# Template JSON
input_template = st.text_area('Template JSON', height=300)
if st.button('Transform'):
try:
data = json.loads(input_json)
template = json.loads(input_template)
transformed = transform_json(data, template)
st.write('Transformed JSON:')
st.json(transformed)
except json.JSONDecodeError:
st.error('Invalid JSON format')
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?