diff --git a/post_parser.py b/post_parser.py
index 240eaf3..852c575 100644
--- a/post_parser.py
+++ b/post_parser.py
@@ -303,9 +303,25 @@ class PostParser:
# Add raw JSON debug output if debug is enabled
if debug:
- debug_json = json.dumps(message, indent=2, ensure_ascii=False, default=str)
- debug_json = debug_json.replace('\\', '').replace('"{', '{').replace('}"', '}').replace('\n', '
')
- html_content.append(f'
{debug_json}')
+ try:
+ # Convert the message to a dictionary
+ message_dict = message.__dict__
+ # Format JSON properly with indents
+ debug_json = json.dumps(message_dict, indent=4, ensure_ascii=False, default=str)
+
+ # Create a div for JSON display with proper styling
+ json_lines = debug_json.split('\n')
+ json_html = []
+ for line in json_lines:
+ # HTML escape each line individually
+ escaped_line = html.escape(line)
+ json_html.append(f'