ElectronNET/Electron.NET · error · JsonException
Unexpected end while reading array.
Error message
Unexpected end while reading array.
What it means
JsonToBoxedPrimitivesConverter.ReadValue, when parsing a JSON array into a List<object>, throws this JsonException if the reader is exhausted before the EndArray token is reached. It signals the JSON stream ended while still inside an array.
Solutions
- Close all arrays with ']' and validate the JSON before sending
- Check the transport layer for truncation of large payloads
- Log the raw payload on failure to locate the cut point
- Round-trip through JSON.parse on the sender to catch malformed output
Example fix
// before var json = "[1, 2, 3"; // missing ] // after var json = "[1, 2, 3]";
Defensive patterns
Strategy: try-catch
Validate before calling
bool isCompleteArray(string json) =>
json.TrimStart().StartsWith("[") && json.TrimEnd().EndsWith("]"); Try / catch
try
{
var value = JsonSerializer.Deserialize<object>(json, ElectronJson.Options);
}
catch (JsonException ex)
{
logger.LogWarning(ex, "Incomplete JSON array: {Raw}", json);
} Prevention
- Serialize arrays with JSON.stringify instead of manual string building
- Ensure transports don't truncate large arrays
- Round-trip JSON.parse on the sender to validate output
When it happens
Trigger: An array missing its closing bracket, e.g. '[1, 2, 3' with no ']', or the stream ending mid-array during IPC transmission.
Common situations: Truncated IPC payloads; building arrays via string concatenation and dropping the closing bracket; incomplete reads from a stream.
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
- Unexpected end while reading property value.
- Unexpected end while reading object.
- Expected property name.
- Unknown release notes format.
- Could not parse version from release notes header.
AI-assisted analysis of ElectronNET/Electron.NET@87cc6f98b6 (2026-09-14).
Data as JSON: /api/errors/536d2f46697a3606.
Report an issue: GitHub.
Appendix: source
Thrown at src/ElectronNET.API/Serialization/JsonToBoxedPrimitivesConverter.cs:58
obj[name] = ReadValue(ref r);
}
throw new JsonException("Unexpected end while reading object.");
case JsonTokenType.StartArray:
var list = new List<object>();
while (r.Read())
{
if (r.TokenType == JsonTokenType.EndArray)
{
return list;
}
list.Add(ReadValue(ref r));
}
throw new JsonException("Unexpected end while reading array.");
case JsonTokenType.True: return true;
case JsonTokenType.False: return false;
case JsonTokenType.Null: return null;
case JsonTokenType.Number:
if (r.TryGetInt32(out int i))
{
return i;
}
if (r.TryGetInt64(out long l))
{
return l;
}
if (r.TryGetDouble(out double d))View on GitHub (pinned to 87cc6f98b6)