elsa-workflows/elsa-core · error · JsonException
Expected an array of strings.
Error message
Expected an array of strings.
What it means
CaseInsensitiveHashSetConverter.Read deserializes a HashSet<string> of secret tags. If the JSON token is neither null nor a start-array, the converter throws this JsonException because only a JSON array is a valid representation for tags. This indicates malformed or incompatible stored/serialized JSON for the Tags property.
Solutions
- Fix the JSON so tags is an array of strings, e.g. "tags": ["prod", "api"].
- If the value should be empty, set it to null (converter returns an empty set) or an empty array [].
- Migrate old-format documents to the current Secret JSON schema.
- Validate external JSON against the Secret schema before deserializing.
Example fix
// before
{ "tags": "prod,api" }
// after
{ "tags": ["prod", "api"] } Defensive patterns
Strategy: validation
Validate before calling
using var doc = JsonDocument.Parse(json);
if (doc.RootElement.TryGetProperty("tags", out var t) && t.ValueKind is not (JsonValueKind.Array or JsonValueKind.Null))
throw new JsonException("'tags' must be an array of strings."); Type guard
static bool IsValidTagsJson(JsonElement el) => el.ValueKind is JsonValueKind.Array or JsonValueKind.Null;
Try / catch
try { return JsonSerializer.Deserialize<Secret>(json, options); }
catch (JsonException ex) when (ex.Message.Contains("array of strings")) { /* repair tags field or reject payload */ } Prevention
- Always serialize tags as a JSON array of strings.
- Validate secret JSON before storing or deserializing.
- Use the same serializer options the repository uses when writing documents manually.
When it happens
Trigger: Deserializing a Secret (or payload containing Tags) where the tags field is a string, object, or number instead of a JSON array — e.g. stored data from an older schema or hand-edited JSON.
Common situations: Manual database edits of secret documents; data produced by a different serializer or library version; feeding user-supplied JSON into a Secret-shaped model without validation.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Expected a string tag.
- Expected an object of string metadata values.
- Cannot deserialize to .
- Failed to deserialize
- The binding to activity type
AI-assisted analysis of elsa-workflows/elsa-core@fe9217bdfa (2026-09-13).
Data as JSON: /api/errors/8a7cf0332e11c258.
Report an issue: GitHub.
Appendix: source
Thrown at src/modules/Elsa.Secrets/Models/CaseInsensitiveHashSetConverter.cs:14
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Elsa.Secrets.Models;
public class CaseInsensitiveHashSetConverter : JsonConverter<HashSet<string>>
{
public override HashSet<string> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.Null)
return new HashSet<string>(StringComparer.OrdinalIgnoreCase);
if (reader.TokenType != JsonTokenType.StartArray)
throw new JsonException("Expected an array of strings.");
var values = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
while (reader.Read())
{
if (reader.TokenType == JsonTokenType.EndArray)
return values;
if (reader.TokenType != JsonTokenType.String)
throw new JsonException("Expected a string tag.");
var value = reader.GetString();
if (!string.IsNullOrWhiteSpace(value))
values.Add(value);
}
throw new JsonException("Unexpected end of JSON while reading secret tags.");
}
View on GitHub (pinned to fe9217bdfa)