Hi,
I am wondering does st.download_button support downloading JSON format file?
Thank you!!
BR,
Chieh
Hi,
I am wondering does st.download_button support downloading JSON format file?
Thank you!!
BR,
Chieh
Hi @Chieh
It’s certainly possible! Here’s a working example:
import streamlit as st
import json
data = {
"employees": [
{"name": "John Doe", "department": "Marketing", "place": "Remote"},
{"name": "Jane Doe", "department": "Software Engineering", "place": "Remote"},
{"name": "Don Joe", "department": "Software Engineering", "place": "Office"},
]
}
json_string = json.dumps(data)
st.json(json_string, expanded=True)
st.download_button(
label="Download JSON",
file_name="data.json",
mime="application/json",
data=json_string,
)
Happy Streamlit-ing!
Snehan
hi @snehankekre
Thanks for your solution!!
Got it!!
I don’t know even if st.download_button can support receiving the data format from json.dumps()
.
Thanks for your demonstration.
BR,
Chieh
Happy to help!
In such situations, I would encourage you to try to see if it works anyway! Even if it had failed, there’s something to be learned from it.
Got it!!
I have tested it and it does work!!
Thanks for your encouragement.