ElectronNET/Electron.NET · error · JsonException

Expected property name.

Error message

Expected property name.

What it means

JsonToBoxedPrimitivesConverter.ReadValue parses a JSON object into a Dictionary<string, object> of boxed primitives. After reading a start-object token it loops expecting each iteration to begin with a property-name token; any other token inside the object raises this JsonException. It typically indicates malformed or structurally unexpected JSON reaching the converter.

Solutions

  1. Validate the JSON payload with a linter or JSON.parse before sending
  2. Use JSON.stringify instead of manual string construction in JS
  3. Log the raw payload when the error occurs to spot the malformed section
  4. Ensure no trailing commas inside objects

Example fix

// before
const payload = '{ "width": 800, }'; // trailing comma
// after
const payload = JSON.stringify({ width: 800 });
Defensive patterns

Strategy: try-catch

Validate before calling

// sender side
try { JSON.parse(payload); } catch (e) { throw new Error('Invalid JSON payload: ' + e.message); }

Try / catch

try
{
    var value = JsonSerializer.Deserialize<object>(json, ElectronJson.Options);
}
catch (JsonException ex)
{
    logger.LogWarning(ex, "Malformed JSON: {Raw}", json);
}

Prevention

When it happens

Trigger: A '{' followed immediately by a value token (e.g. '{123}' or '{,}'), a trailing comma where a property name was expected, or corrupted/truncated JSON inside an object passed through this converter.

Common situations: Hand-built JSON in client-side JS with syntax errors; string concatenation building payloads instead of JSON.stringify; truncated IPC messages.

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 ElectronNET/Electron.NET@87cc6f98b6 (2026-09-14). Data as JSON: /api/errors/62f74c641a40f3a8. Report an issue: GitHub.

Appendix: source

Thrown at src/ElectronNET.API/Serialization/JsonToBoxedPrimitivesConverter.cs:31

        }

        private static object ReadValue(ref Utf8JsonReader r)
        {
            switch (r.TokenType)
            {
                case JsonTokenType.StartObject:

                    var obj = new Dictionary<string, object>();
                    while (r.Read())
                    {
                        if (r.TokenType == JsonTokenType.EndObject)
                        {
                            return obj;
                        }

                        if (r.TokenType != JsonTokenType.PropertyName)
                        {
                            throw new JsonException("Expected property name.");
                        }

                        string name = r.GetString()!;
                        if (!r.Read())
                        {
                            throw new JsonException("Unexpected end while reading property value.");
                        }

                        obj[name] = ReadValue(ref r);
                    }

                    throw new JsonException("Unexpected end while reading object.");

                case JsonTokenType.StartArray:

                    var list = new List<object>();
                    while (r.Read())
                    {

View on GitHub (pinned to 87cc6f98b6)