elsa-workflows/elsa-core · error · JsonException
Expected end of object.
Error message
Expected end of object.
What it means
PolymorphicDictionaryConverter.Read loops reader.Read() until EndObject to finish consuming the dictionary. If the stream ends (Read returns false) before the closing brace is seen, it throws JsonException("Expected end of object."). It signals unbalanced/unterminated JSON objects.
Solutions
- Repair the truncated JSON (add the missing closing brace) or regenerate the payload.
- Check for size limits on the storage or transport layer (column length, HTTP body limits) that clip the JSON.
- Validate JSON completeness before deserializing.
- Re-export the workflow or instance data from the source system.
Example fix
// before (truncated)
{ "key1": { "nested": 1 }, "key2": { "x": 2
// after
{ "key1": { "nested": 1 }, "key2": { "x": 2 } } Defensive patterns
Strategy: validation
Validate before calling
bool balanced = json.Count(c => c == '{') == json.Count(c => c == '}');
if (!balanced) throw new InvalidOperationException("JSON payload appears truncated (unbalanced braces)"); Type guard
static bool IsCompleteJsonObject(string s) { try { using var d = JsonDocument.Parse(s); return d.RootElement.ValueKind == JsonValueKind.Object; } catch { return false; } } Try / catch
try { var d = JsonSerializer.Deserialize<IDictionary<string, object>>(json); } catch (JsonException ex) when (ex.Message == "Expected end of object.") { log.LogError(ex, "Truncated dictionary JSON"); /* regenerate payload */ } Prevention
- Check for body/column size limits clipping stored JSON (increase max lengths)
- Validate completeness of JSON before deserializing payloads from queues or DB
- Monitor upstream producers for partial writes
When it happens
Trigger: Deserializing a truncated JSON object — missing closing brace — where the while(reader.Read()) loop exhausts the buffer in PolymorphicDictionaryConverter.Read (src/modules/Elsa.Workflows.Core/Serialization/Converters/PolymorphicDictionaryConverter.cs:40).
Common situations: Cut-off HTTP response bodies; database blobs truncated by column size limits; log-export pipelines clipping long JSON strings.
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
- Cannot determine the element type of array
- Expected start of object.
- Failed to extract activity type property
- Failed to parse JsonDocument
- Runtime entity definition document
AI-assisted analysis of elsa-workflows/elsa-core@fe9217bdfa (2026-09-13).
Data as JSON: /api/errors/51b8d11041cffd73.
Report an issue: GitHub.
Appendix: source
Thrown at src/modules/Elsa.Workflows.Core/Serialization/Converters/PolymorphicDictionaryConverter.cs:40
public override IDictionary<string, object> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType != JsonTokenType.StartObject)
throw new JsonException("Expected start of object.");
var dictionary = new Dictionary<string, object>();
while (reader.Read())
{
if (reader.TokenType == JsonTokenType.EndObject)
return dictionary;
var key = reader.GetString()!;
reader.Read();
var value = _objectConverter.Read(ref reader, typeof(object), options)!;
dictionary.Add(key, value);
}
throw new JsonException("Expected end of object.");
}
/// <inheritdoc />
public override void Write(Utf8JsonWriter writer, IDictionary<string, object> value, JsonSerializerOptions options)
{
writer.WriteStartObject();
foreach (var kvp in value)
{
writer.WritePropertyName(kvp.Key);
_objectConverter.Write(writer, kvp.Value, options);
}
writer.WriteEndObject();
}
}
View on GitHub (pinned to fe9217bdfa)