MCPcopy Create free account
hub / github.com/encode/starlette / send_json

Method send_json

starlette/websockets.py:177–184  ·  view source on GitHub ↗
(self, data: Any, mode: str = "text")

Source from the content-addressed store, hash-verified

175 await self.send({"type": "websocket.send", "bytes": data})
176
177 async def send_json(self, data: Any, mode: str = "text") -> None:
178 if mode not in {"text", "binary"}:
179 raise RuntimeError('The "mode" argument should be "text" or "binary".')
180 text = json.dumps(data, separators=(",", ":"), ensure_ascii=False)
181 if mode == "text":
182 await self.send({"type": "websocket.send", "text": text})
183 else:
184 await self.send({"type": "websocket.send", "bytes": text.encode("utf-8")})
185
186 async def close(self, code: int = 1000, reason: str | None = None) -> None:
187 await self.send({"type": "websocket.close", "code": code, "reason": reason or ""})

Callers 15

appFunction · 0.95
test_websocket_iter_jsonFunction · 0.95
__call__Method · 0.95
__call__Method · 0.95
websocket_stateFunction · 0.45
on_receiveMethod · 0.45

Calls 1

sendMethod · 0.95