Does st.download_button support downloading json format?

Hi,

I am wondering does st.download_button support downloading JSON format file?

Thank you!!

BR,
Chieh

1 Like

Hi @Chieh :wave:

It’s certainly possible! Here’s a working example:

Code

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,
)

Output

download-json

Happy Streamlit-ing! :balloon:
Snehan

1 Like

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. :smile:

Got it!!

I have tested it and it does work!!

Thanks for your encouragement. :smiley:

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.