diff --git a/starlette/testclient.py b/starlette/testclient.py index bdae83bf0..a66b901d6 100644 --- a/starlette/testclient.py +++ b/starlette/testclient.py @@ -145,7 +145,7 @@ def send_bytes(self, data: bytes) -> None: def send_json(self, data: typing.Any, mode: str = "text") -> None: assert mode in ["text", "binary"] - text = json.dumps(data) + text = json.dumps(data, separators=(",", ":")) if mode == "text": self.send({"type": "websocket.receive", "text": text}) else: diff --git a/starlette/websockets.py b/starlette/websockets.py index afcbde7fc..e89579235 100644 --- a/starlette/websockets.py +++ b/starlette/websockets.py @@ -168,7 +168,7 @@ async def send_bytes(self, data: bytes) -> None: async def send_json(self, data: typing.Any, mode: str = "text") -> None: if mode not in {"text", "binary"}: raise RuntimeError('The "mode" argument should be "text" or "binary".') - text = json.dumps(data) + text = json.dumps(data, separators=(",", ":")) if mode == "text": await self.send({"type": "websocket.send", "text": text}) else: