Websocket send JSON encoded bytes #1576
-
Hello, |
Beta Was this translation helpful? Give feedback.
Answered by
Kludex
Jan 14, 2024
Replies: 1 comment
-
You can use the following from typing import Any
import orjson
from starlette.websockets import WebSocket
async def send_json(websocket: WebSocket, data: dict[str, Any]):
text = orjson.dumps(data)
await websocket.send({"type": "websocket.send", "text": text}) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Kludex
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use the following
send_json
function: