elsa-workflows/elsa-core · error · JsonException
Unexpected end of JSON while reading secret metadata.
Error message
Unexpected end of JSON while reading secret metadata.
What it means
After reading a metadata property name, the converter reads the next token for the value; if the reader is exhausted (no more tokens) the JSON ended mid-property and this JsonException is thrown. Like error 306, it signals truncated/incomplete JSON, here inside the secret metadata object.
Solutions
- Repair or re-save the secret document so the metadata object is complete.
- Restore the document from backup if the value is unrecoverable.
- Check storage column sizes/encoding for truncation causes.
- Parse-validate JSON completeness before persisting or forwarding it.
Example fix
// before (truncated)
{ "metadata": { "env":
// after
{ "metadata": { "env": "prod" } } Defensive patterns
Strategy: validation
Validate before calling
try { using var _ = JsonDocument.Parse(json); } catch (JsonException) { throw new InvalidOperationException("Secret JSON is truncated or malformed."); } Try / catch
try { var secret = JsonSerializer.Deserialize<Secret>(json, options); }
catch (JsonException ex) when (ex.Message.Contains("Unexpected end of JSON")) { /* reload from backup or re-create the secret */ } Prevention
- Parse-validate JSON before storing it in custom stores.
- Ensure storage columns can hold the full payload.
- Detect and retry failed/partial writes during saves.
When it happens
Trigger: Deserializing a Secret whose JSON ends right after a metadata property name, e.g. "metadata": { "env": — from a truncated write, cut-off response, or manually clipped document.
Common situations: Storage truncation (column size limits), interrupted writes/crashes mid-save, or manually pasted JSON missing its tail.
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.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Unexpected end of JSON while reading secret tags.
- Expected a metadata property name.
- Expected an object of string metadata values.
- Expected end of object.
- Stored secret document
AI-assisted analysis of elsa-workflows/elsa-core@fe9217bdfa (2026-09-13).
Data as JSON: /api/errors/f24943d6dd8c6ae0.
Report an issue: GitHub.
Appendix: source
Thrown at src/modules/Elsa.Secrets/Models/OrdinalIgnoreCaseDictionaryConverter.cs:27
{
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.");
}
public override void Write(Utf8JsonWriter writer, IDictionary<string, string> value, JsonSerializerOptions options)
{
writer.WriteStartObject();View on GitHub (pinned to fe9217bdfa)