elsa-workflows/elsa-core · error · JsonException

Expected a metadata property name.

Error message

Expected a metadata property name.

What it means

While iterating the metadata object, OrdinalIgnoreCaseDictionaryConverter.Read expects each token to be a property name; any other token triggers this JsonException. It indicates a malformed metadata object rather than a wrong overall shape.

Solutions

  1. Repair the metadata object so every value is preceded by a property name.
  2. Re-save the secret through the repository API rather than editing stored JSON.
  3. Restore the document from a backup if it cannot be repaired.
  4. Use a standard serializer (System.Text.Json) to generate metadata JSON, never string concatenation.

Example fix

// before (malformed)
{ "metadata": { "env" "prod" } }

// after
{ "metadata": { "env": "prod" } }
Defensive patterns

Strategy: validation

Validate before calling

try { using var doc = JsonDocument.Parse(json); var m = doc.RootElement.GetProperty("metadata"); if (m.ValueKind == JsonValueKind.Object) { foreach (var p in m.EnumerateObject()) _ = p.Name; } } catch (JsonException) { throw new InvalidOperationException("Metadata JSON is malformed."); }

Try / catch

try { var secret = JsonSerializer.Deserialize<Secret>(json, options); }
catch (JsonException ex) when (ex.Message.Contains("property name")) { /* repair or reject the document */ }

Prevention

When it happens

Trigger: Deserializing a metadata object whose contents are malformed — e.g. non-property tokens inside the object because of corrupted JSON like { "env" "prod" } (missing colon) or a value token sequence produced by a buggy writer.

Common situations: Corrupted stored documents from partial writes; JSON produced by hand-rolled serialization that skips property names; manual edits that dropped a key.

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 elsa-workflows/elsa-core@fe9217bdfa (2026-09-13). Data as JSON: /api/errors/ad0deb694b030a12. Report an issue: GitHub.

Appendix: source

Thrown at src/modules/Elsa.Secrets/Models/OrdinalIgnoreCaseDictionaryConverter.cs:23

public class OrdinalIgnoreCaseDictionaryConverter : JsonConverter<IDictionary<string, string>>
{
    public override IDictionary<string, string> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
    {
        if (reader.TokenType == JsonTokenType.Null)
            return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

        if (reader.TokenType != JsonTokenType.StartObject)
            throw new JsonException("Expected an object of string metadata values.");

        var values = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
        while (reader.Read())
        {
            if (reader.TokenType == JsonTokenType.EndObject)
                return values;

            if (reader.TokenType != JsonTokenType.PropertyName)
                throw new JsonException("Expected a metadata property name.");

            var key = reader.GetString()!;
            if (!reader.Read())
                throw new JsonException("Unexpected end of JSON while reading secret metadata.");

            if (reader.TokenType == JsonTokenType.Null)
                continue;

            if (reader.TokenType != JsonTokenType.String)
                throw new JsonException("Expected a string metadata value.");

            var value = reader.GetString();
            if (value != null)
                values[key] = value;
        }

        throw new JsonException("Unexpected end of JSON while reading secret metadata.");
    }

View on GitHub (pinned to fe9217bdfa)