Hey guys,
Do you know if there is some UI control that can display formatted JSON?
Something like is available in Anvil Tables for simple object type of column?
As a temporary solution I made conversion from JSON to Markdown so the code can be displayed formatted in the RichText control.
See below the python code if someone is interested.
import json
# JSON data with results
json_data = self.item['outcomes']
# Sort keys to maintain order
sorted_keys = sorted(json_data, key=lambda x: int(x[1:]))
# Generate Markdown
markdown_output = ""
for key in sorted_keys:
item = json_data[key]
result = item['result']
if isinstance(result, list):
result_text = ", ".join(str(r) if r is not None else 'N/A' for r in result)
else:
result_text = str(result)
markdown_output += f"##### {item['text']}\n- **Result**: {result_text}\n\n"
self.rich_text_1.content = markdown_output
Sample end result:
py.space code snippet: