{"record":{"id":"51b8d11041cffd73","repo":"elsa-workflows/elsa-core","slug":"expected-end-of-object","errorCode":null,"errorMessage":"Expected end of object.","messagePattern":"Expected end of object\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Workflows.Core/Serialization/Converters/PolymorphicDictionaryConverter.cs","lineNumber":40,"sourceCode":"    public override IDictionary<string, object> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)\n    {\n        if (reader.TokenType != JsonTokenType.StartObject)\n            throw new JsonException(\"Expected start of object.\");\n\n        var dictionary = new Dictionary<string, object>();\n\n        while (reader.Read())\n        {\n            if (reader.TokenType == JsonTokenType.EndObject)\n                return dictionary;\n\n            var key = reader.GetString()!;\n            reader.Read();\n            var value = _objectConverter.Read(ref reader, typeof(object), options)!;\n            dictionary.Add(key, value);\n        }\n\n        throw new JsonException(\"Expected end of object.\");\n    }\n\n    /// <inheritdoc />\n    public override void Write(Utf8JsonWriter writer, IDictionary<string, object> value, JsonSerializerOptions options)\n    {\n        writer.WriteStartObject();\n\n        foreach (var kvp in value)\n        {\n            writer.WritePropertyName(kvp.Key);\n            _objectConverter.Write(writer, kvp.Value, options);\n        }\n\n        writer.WriteEndObject();\n    }\n}\n","sourceCodeStart":22,"sourceCodeEnd":57,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Workflows.Core/Serialization/Converters/PolymorphicDictionaryConverter.cs#L22-L57","documentation":"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.","triggerScenarios":"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).","commonSituations":"Cut-off HTTP response bodies; database blobs truncated by column size limits; log-export pipelines clipping long JSON strings.","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."],"exampleFix":"// before (truncated)\n{ \"key1\": { \"nested\": 1 }, \"key2\": { \"x\": 2\n\n// after\n{ \"key1\": { \"nested\": 1 }, \"key2\": { \"x\": 2 } }","handlingStrategy":"validation","validationCode":"bool balanced = json.Count(c => c == '{') == json.Count(c => c == '}');\nif (!balanced) throw new InvalidOperationException(\"JSON payload appears truncated (unbalanced braces)\");","typeGuard":"static bool IsCompleteJsonObject(string s) { try { using var d = JsonDocument.Parse(s); return d.RootElement.ValueKind == JsonValueKind.Object; } catch { return false; } }","tryCatchPattern":"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 */ }","preventionTips":["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"],"tags":["csharp","json","serialization","truncation"],"backgroundTag":"json-parse-error","analyzedSha":"fe9217bdfa0e27f0e09e45006eb6898f616e513d","analyzedAt":"2026-09-13T20:32:34.702Z","contentChangedAt":"2026-09-13T20:32:34.702Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}