Getting data back as list of dictionaries when using Streamlit-ace

Summary

Hi Community!
I have a streamlit-ace editor in my code for json format. The input for this editor is a list of dictionaries, but when a user makes any changes, it converts to a string. I want it back as a list of dictionaries

Steps to reproduce

Code snippet:

content = st_ace(value=json.dumps(st.session_state.json_, indent=2), language="json", theme="clouds_midnight")
print(type(content), type(st.session_state.json_))

Expected behavior:
I want to receive it back as a list of dictionaries - [{},{},{}], instead I get โ€œ[โ€{},{},{}โ€œ]โ€
The bad part is, inside my json there are other string values, so this list becomes a list of 4 elements, maybe 5โ€ฆ
Like, one string is -
{
โ€œexpectation_typeโ€: โ€œexpect_column_values_to_be_in_setโ€,
โ€œmetaโ€: {},
โ€œkwargsโ€: {
โ€œvalue_setโ€: [
โ€œ41,-70โ€,
โ€œ42
second string is -
-70โ€,
โ€œ42
third string is -
-71โ€,
โ€œ42,-70โ€,
โ€œ42,-71โ€,
โ€œ42,-72โ€,
โ€œ42,-73โ€,
"43

Actual behavior:
Before making any changes, type for st.session_state.json_ is <class โ€˜listโ€™>, after running and saving editor content, itโ€™s string.
I just need it back as the format it was in.
Is there any way to do that?
Thanks in advance!

Hi Community!
I was able to get this done by using json.loads(content)

1 Like

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