elsa-workflows/elsa-core · error · JsonException
Expected number or string.
Error message
Expected number or string.
What it means
BigIntegerJsonConverter.Read deserializes a JSON token into a BigInteger, accepting only JSON numbers and strings parseable as long. Any other token type (true, false, null, object, array, etc.) causes a JsonException with the message 'Expected number or string.'
Solutions
- Fix the JSON payload so the field is a number or a numeric string.
- Make the property nullable or use JsonIgnoreCondition so nulls bypass the converter.
- Use a custom converter override (or Read handling JsonTokenType.Null) if null must be accepted.
- Verify the converter is only applied to properties that are actually numeric.
Example fix
// before
{"count": null}
// after
{"count": 42} Defensive patterns
Strategy: validation
Validate before calling
if (token.Type is not (JsonTokenType.Number or JsonTokenType.String))
throw new JsonException($"Expected number or string for BigInteger, got {token.Type}."); Type guard
bool IsBigIntegerToken(JsonTokenType t) => t is JsonTokenType.Number or JsonTokenType.String;
Try / catch
try { var value = JsonSerializer.Deserialize<BigInteger>(json, options); }
catch (JsonException ex) { log.LogWarning(ex, "Invalid BigInteger payload"); value = BigInteger.Zero; } Prevention
- Contract-test payloads against the converter's accepted token types.
- Handle JsonTokenType.Null explicitly if nullable semantics are needed.
- Keep converter applicability limited to numeric properties.
When it happens
Trigger: Deserializing JSON where a field bound to BigInteger holds a non-numeric, non-string token — e.g. true/false/null, a nested object, or an array.
Common situations: API responses returning null for a numeric field; payload shape changes upstream; wiring the converter onto a bool or object property by mistake.
Understand the failure class
Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.
Related errors
- Cannot convert to bool
- Expected an EndObject token
- 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/09bad3a4f37922fb.
Report an issue: GitHub.
Appendix: source
Thrown at src/modules/Elsa.Common/Converters/BigIntegerJsonConverter.cs:24
/// <summary>
/// Converts big integers to and from JSON strings.
/// </summary>
public class BigIntegerJsonConverter : JsonConverter<BigInteger>
{
/// <inheritdoc />
public override BigInteger Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.Number)
return reader.GetInt64();
if (reader.TokenType == JsonTokenType.String)
{
var value = reader.GetString()!;
return long.Parse(value);
}
throw new JsonException("Expected number or string.");
}
/// <inheritdoc />
public override void Write(Utf8JsonWriter writer, BigInteger value, JsonSerializerOptions options)
{
// Write the Big Integer as a JSON number.
writer.WriteNumberValue((long)value);
}
}View on GitHub (pinned to fe9217bdfa)