Repository navigation
[BUG] Web PubSub client encodes JSON payloads as strings #50963
Description
Describe the bug
WebPubSubClient.sendToGroup and sendEvent encode WebPubSubDataFormat.JSON payloads as escaped JSON strings instead of native JSON values in the reliable JSON protocol frame.
For example, sending {"key":"value"} with WebPubSubDataFormat.JSON produces:
{
"dataType": "json",
"data": "{\"key\":\"value\"}"
}The dataType declares JSON, but the data field is a string. A receiver expecting a typed JSON value cannot process the payload as a JSON object.
No exception is necessarily raised by the client because the Web PubSub service can acknowledge the frame before the receiver attempts to process its contents.
To Reproduce
- Create and start a
WebPubSubClientusing the reliable JSON protocol. - Send a JSON payload using either
sendToGrouporsendEvent. - Inspect the outgoing reliable JSON frame or the value delivered to the receiver.
Code Snippet
BinaryData payload = BinaryData.fromString("{\"key\":\"value\"}");
client.sendToGroup("group", payload, WebPubSubDataFormat.JSON);
client.sendEvent("event", payload, WebPubSubDataFormat.JSON);Both outgoing message serializers currently call writeStringField("data", ...), which escapes the serialized JSON:
SendToGroupMessage.toJsonSendEventMessage.toJson
Expected behavior
JSON payloads should be written as native JSON values:
{
"dataType": "json",
"data": {
"key": "value"
}
}TEXT, BINARY, and PROTOBUF payload encoding should remain unchanged.
Setup (please complete the following information):
- OS: Any
- IDE: N/A
- Library/Libraries:
com.azure:azure-messaging-webpubsub-client:1.1.11; also reproducible on the currentmainbranch for1.2.0-beta.1 - Java version: Java 8 or later
- App Server/Environment: Standalone Java application
- Frameworks: None
Additional context
The incoming GroupDataMessage and ServerDataMessage serializers already preserve JSON values with writeRawField, so outgoing messages should use the same JSON encoding semantics.
Information Checklist
- Bug Description Added
- Repro Steps Added
- Setup information Added
Activity
github-actions commentedon Oct 23, 2026
Thank you for your feedback. Tagging and routing to the team member(s) best able to assist.
//cc: Ken Chen (@chenkennt) Liangying.Wei (@vicancy)
github-actions commentedon Oct 23, 2026
🎯 Agentic Issue Triage
Summary:
WebPubSubClient.sendToGroup/sendEventwrite JSON-format payloads as escaped strings (writeStringField) rather than native JSON values in the reliable JSON protocol frame.📋 Issue Details
Package:
com.azure:azure-messaging-webpubsub-client(1.1.11; also on main 1.2.0-beta.1)Affected API:
SendToGroupMessage.toJson,SendEventMessage.toJsonScenarios:
sendToGroupwithWebPubSubDataFormat.JSONsendEventwithWebPubSubDataFormat.JSONRoot ask: Write JSON payloads as native JSON (e.g.
writeRawField), as incomingGroupDataMessage/ServerDataMessagealready do; leave TEXT/BINARY/PROTOBUF unchanged.🔎 Debugging / Reproduction Notes
Reporter has already identified the likely cause.
Suggested investigation steps:
writeStringField("data", ...)towriteRawFieldfor the JSON data type in both classes.datais a JSON object for JSON format and unchanged for other formats.🏷️ Label Confidence
Client— SDK code behavior.WebPubSub— package azure-messaging-webpubsub-client.👥 Owner Routing
# ServiceLabel: %WebPubSub(line 491)@chenkennt@vicancy%Mgmt(line 945) did not match since the category is Client.