{"record":{"id":"369725b2367cf001","repo":"microsoft/aspire","slug":"unexpected-end-of-json-while-reading-role-value","errorCode":null,"errorMessage":"Unexpected end of JSON while reading role value.","messagePattern":"Unexpected end of JSON while reading role value\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Dashboard/Model/GenAI/GenAIMessageParsingHelper.cs","lineNumber":117,"sourceCode":"        {\n            if (reader.TokenType == JsonTokenType.EndObject)\n            {\n                break;\n            }\n\n            if (reader.TokenType != JsonTokenType.PropertyName)\n            {\n                throw new JsonException(\"Expected property name.\");\n            }\n\n            var propertyName = reader.GetString();\n\n            switch (propertyName)\n            {\n                case \"role\":\n                    if (!reader.Read())\n                    {\n                        throw new JsonException(\"Unexpected end of JSON while reading role value.\");\n                    }\n                    role = reader.GetString();\n                    break;\n                case \"parts\":\n                    // DeserializeArrayIncrementally reads the StartArray token itself.\n                    (parts, partsTruncated) = DeserializeArrayIncrementally<MessagePart>(ref reader, ReadMessagePart);\n                    break;\n                default:\n                    if (!reader.Read())\n                    {\n                        throw new JsonException(\"Unexpected end of JSON while reading property value.\");\n                    }\n\n                    if (!reader.TrySkip())\n                    {\n                        throw new JsonException(\"Unexpected end of JSON while skipping property value.\");\n                    }\n                    break;","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Dashboard/Model/GenAI/GenAIMessageParsingHelper.cs#L99-L135","documentation":"In ReadChatMessage, after the \"role\" property name the parser must read the next token to get the role string. If reader.Read() returns false, the UTF-8 buffer ended inside the object, so the role value is unavailable and JsonException is thrown. Utf8JsonReader is non-buffering, so a truncated input is unrecoverable here.","triggerScenarios":"Parsing a chat message JSON string that terminates immediately after \"role\" with no value, e.g. {\"role\" — the reader hits end of data instead of the role string token.","commonSituations":"Telemetry bodies truncated by a size cap exactly inside the role field; corrupted or partially written exported trace files; manual edits of recorded payloads.","solutions":["Verify the stored message JSON is complete and well-formed (e.g. with a JSON linter) before the dashboard parses it","Re-export telemetry with larger body/attribute size limits so the message is not cut mid-field","Regenerate the telemetry entry from the source application if the export was truncated","Handle JsonException in the visualizer path and show the raw body as an error placeholder instead of throwing"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"using var doc = JsonDocument.Parse(json); // throws earlier with a clearer message if truncated\nif (!doc.RootElement.TryGetProperty(\"role\", out var role) || role.ValueKind != JsonValueKind.String)\n    throw new FormatException(\"Chat message JSON is truncated or role is missing.\");","typeGuard":"static bool HasCompleteRole(JsonElement e) =>\n    e.ValueKind == JsonValueKind.Object &&\n    e.TryGetProperty(\"role\", out var r) && r.ValueKind == JsonValueKind.String;","tryCatchPattern":"try { ParseChatMessage(json); }\ncatch (JsonException ex) when (ex.Message.Contains(\"Unexpected end of JSON\"))\n{\n    logger.LogWarning(\"Truncated GenAI message payload: {Reason}\", ex.Message);\n}","preventionTips":["Increase telemetry body size limits so payloads are not clipped mid-field","Round-trip exported JSON through a validator before re-importing","Detect truncation at export time and mark bodies as incomplete"],"tags":["json","truncated-input","genai","parsing"],"backgroundTag":"json-parse-error","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}