microsoft/aspire · error · JsonException

Unexpected end of JSON while reading property value.

Error message

Unexpected end of JSON while reading property value.

What it means

ReadChatMessage hits a property name it does not recognize (default case) and calls reader.Read() to move to the property's value. If the reader has no more data the JSON is truncated inside the object, so JsonException is thrown. The parser only knows how to skip unknown values, not reconstruct them.

Solutions

  1. Ensure the full message JSON is present — re-export or re-read the telemetry without truncation
  2. Validate the payload with JsonDocument.Parse first to catch malformed bodies before incremental parsing
  3. If a vendor adds fields, update the Aspire Dashboard so known properties are parsed rather than relying on the skip path
  4. Catch JsonException around message parsing and fall back to showing the raw content
Defensive patterns

Strategy: try-catch

Validate before calling

using var doc = JsonDocument.Parse(json);
foreach (var prop in doc.RootElement.EnumerateObject())
    if (prop.Name is not ("role" or "parts") && prop.Value.ValueKind == JsonValueKind.Undefined)
        throw new FormatException($"Property '{prop.Name}' has no value — payload truncated.");

Try / catch

try { ParseChatMessage(json); }
catch (JsonException ex)
{
    logger.LogWarning(ex, "GenAI message could not be parsed; unknown property may be truncated.");
}

Prevention

When it happens

Trigger: A GenAI message object containing an unknown property (any name other than "role" or "parts") whose value token is missing because the JSON ended right after the property name, e.g. {"role":"user","metadata"}.

Common situations: Newer emitter versions add extra message fields that older dashboard parsers skip — truncation at exactly that point surfaces this; clipped OTLP log bodies from exporter size limits.

Understand the failure class

Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/df384be8cc1cf7de. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Dashboard/Model/GenAI/GenAIMessageParsingHelper.cs:128

            var propertyName = reader.GetString();

            switch (propertyName)
            {
                case "role":
                    if (!reader.Read())
                    {
                        throw new JsonException("Unexpected end of JSON while reading role value.");
                    }
                    role = reader.GetString();
                    break;
                case "parts":
                    // DeserializeArrayIncrementally reads the StartArray token itself.
                    (parts, partsTruncated) = DeserializeArrayIncrementally<MessagePart>(ref reader, ReadMessagePart);
                    break;
                default:
                    if (!reader.Read())
                    {
                        throw new JsonException("Unexpected end of JSON while reading property value.");
                    }

                    if (!reader.TrySkip())
                    {
                        throw new JsonException("Unexpected end of JSON while skipping property value.");
                    }
                    break;
            }
        }

        return (role ?? string.Empty, parts ?? [], partsTruncated);
    }

    /// <summary>
    /// If the node is a JSON string that parses to a JSON object or array, return the parsed node instead.
    /// </summary>
    internal static JsonNode? TryParseStringJsonNode(JsonNode? node)
    {

View on GitHub (pinned to 25830f84bd)