{"record":{"id":"e7f6823138af5760","repo":"elsa-workflows/elsa-core","slug":"expected-a-propertyname-token","errorCode":null,"errorMessage":"Expected a PropertyName token","messagePattern":"Expected a PropertyName token","errorType":"validation","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Http/Serialization/HttpHeadersConverter.cs","lineNumber":25,"sourceCode":"/// A custom JSON converter for HttpHeaders that supports both single and multiple values.\n/// </summary>\npublic class HttpHeadersConverter : JsonConverter<HttpHeaders>\n{\n    /// <inheritdoc />\n    public override HttpHeaders Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)\n    {\n        if (reader.TokenType != JsonTokenType.StartObject)\n            throw new JsonException(\"Expected StartObject token\");\n\n        var headers = new HttpHeaders();\n\n        while (reader.Read())\n        {\n            if (reader.TokenType == JsonTokenType.EndObject)\n                return headers;\n\n            if (reader.TokenType != JsonTokenType.PropertyName)\n                throw new JsonException(\"Expected a PropertyName token\");\n\n            var key = reader.GetString()!;\n            reader.Read();\n\n            // If the next token is not a StartArray token, then we expect a String token.\n            switch (reader.TokenType)\n            {\n                case JsonTokenType.StartArray:\n                {\n                    var values = new List<string>();\n                    while (reader.Read() && reader.TokenType != JsonTokenType.EndArray) values.Add(reader.GetString()!);\n                    headers.Add(key, values.ToArray());\n                    break;\n                }\n                case JsonTokenType.String:\n                {\n                    var singleValue = reader.GetString()!;\n                    headers.Add(key, new[] { singleValue });","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Http/Serialization/HttpHeadersConverter.cs#L7-L43","documentation":"While iterating the JSON object, HttpHeadersConverter expects each member to be a property name (a header key). If it encounters a token other than EndObject or PropertyName at the member position, it throws JsonException('Expected a PropertyName token'), guarding against structurally invalid header objects.","triggerScenarios":"Deserializing HttpHeaders from malformed JSON such as a nested array element or a bare value inside the object where a key should be, e.g. {\"Accept\"} or nested objects without keys — typically corrupt or hand-crafted persisted state.","commonSituations":"Corrupted workflow instance state in a durable store; custom code writing headers with the wrong serializer; JSON produced by another language/library that doesn't map header objects cleanly.","solutions":["Repair the JSON so it is a well-formed object of key->string-or-string[] pairs","Re-serialize the headers through HttpHeaders itself instead of hand-writing JSON","Validate with JsonDocument.Parse before deserializing into HttpHeaders","If state is persisted, isolate and delete/repair the corrupt instance state record"],"exampleFix":"// before\n{\"Accept\"} // invalid: missing value, breaks at member position\n// after\n{\"Accept\": [\"text/plain\"]}","handlingStrategy":"type-guard","validationCode":"using var doc = JsonDocument.Parse(json);\nforeach (var prop in doc.RootElement.EnumerateObject())\n    if (prop.Value.ValueKind is not (JsonValueKind.String or JsonValueKind.Array))\n        throw new FormatException($\"Header '{prop.Name}' has invalid value kind {prop.Value.ValueKind}\");","typeGuard":"bool IsValidHeadersObject(JsonElement e) => e.ValueKind == JsonValueKind.Object && e.EnumerateObject().All(p => p.Value.ValueKind is JsonValueKind.String or JsonValueKind.Array);","tryCatchPattern":"try { headers = JsonSerializer.Deserialize<HttpHeaders>(json, options); }\ncatch (JsonException ex)\n{\n    logger.LogWarning(ex, \"Headers JSON is not a valid key/value object\");\n    throw new InvalidDataException(\"Invalid HttpHeaders payload\", ex);\n}","preventionTips":["Never hand-write headers JSON; round-trip through HttpHeaders","Sanitize persisted workflow state after serializer upgrades","Include the deserializing type in persisted-state corruption alerts"],"tags":["json","serialization","http","elsa"],"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-16T04:17:20.429Z"}