pretty print json.

This commit is contained in:
Julien Palard 2023-04-07 22:24:57 +02:00
parent 661f83e38f
commit c2fe3249ea
Signed by: mdk
GPG Key ID: 0EFC1AC1006886F8
1 changed files with 7 additions and 2 deletions

View File

@ -5,13 +5,14 @@ import asyncio
import os
import signal
import socket
import json
import sys
import aioxmpp
import aioxmpp.dispatcher
from aiohttp import web
__version__ = "0.1"
__version__ = "0.2"
class XMPPClient:
@ -55,7 +56,11 @@ class HTTPServer:
async def on_post(self, request):
if not self.xmpp_client:
return
self.xmpp_client.send(await request.text(), self.to_jid)
data = await request.text()
try:
self.xmpp_client.send(json.dumps(json.loads(data), indent=4), self.to_jid)
except json.JSONDecodeError:
self.xmpp_client.send(data, self.to_jid)
return web.Response(text="")