tui-cs/Terminal.Gui · error · JsonException

After {propertyName}: Expected PropertyName but got another

Error message

After {propertyName}: Expected PropertyName but got another token when parsing Attribute: {reader.TokenType}.

What it means

Inside a Scheme object, after reading a property's Attribute value, the next token is not a PropertyName — meaning the JSON structure is malformed (an extra value, a missing comma, or an unexpected nested token where a flat key:value pair was expected).

Source

Thrown at Terminal.Gui/Configuration/SchemeJsonConverter.cs:30

    {
        if (reader.TokenType != JsonTokenType.StartObject)
        {
            throw new JsonException ($"Unexpected StartObject token when parsing Scheme: {reader.TokenType}.");
        }

        var scheme = new Scheme ();
        var propertyName = string.Empty;

        while (reader.Read ())
        {
            if (reader.TokenType == JsonTokenType.EndObject)
            {
                return scheme;
            }

            if (reader.TokenType != JsonTokenType.PropertyName)
            {
                throw new JsonException ($"After {propertyName}: Expected PropertyName but got another token when parsing Attribute: {reader.TokenType}.");
            }

            propertyName = reader.GetString ();
            reader.Read ();

            // Make sure attributes are marked as explicitly set when deserialized
            object? attrObj = JsonSerializer.Deserialize (ref reader, TuiSerializerContext.Instance.Attribute);

            if (attrObj is not Attribute attribute)
            {
                throw new JsonException ($"After {propertyName}: Expected Attribute but got {attrObj?.GetType ().Name ?? "null"} when parsing Scheme.");
            }
            if (propertyName is { })
            {
                scheme = propertyName.ToLowerInvariant () switch
                {
                    "normal" => scheme with { Normal = attribute },
                    "hotnormal" => scheme with { HotNormal = attribute },

View on GitHub (pinned to 2e47b11478)

Solutions

  1. Run the config JSON through a JSON validator/linter to find the syntax error.
  2. Ensure each Scheme entry is flat key:value pairs separated by commas.
  3. Regenerate the config from a known-good default and re-apply edits.

Example fix

// before
{ "Normal": {"Foreground":"White"} "Focus": {"Foreground":"Yellow"} }
// after
{ "Normal": {"Foreground":"White"}, "Focus": {"Foreground":"Yellow"} }
Defensive patterns

Strategy: validation

Validate before calling

// Pre-validate JSON syntax before handing to ConfigurationManager
try { JsonDocument.Parse (File.ReadAllText (path)); }
catch (JsonException ex) { /* report line/position from ex */ }

Try / catch

try { ConfigurationManager.Apply (); }
catch (JsonException ex) when (ex.Message.Contains ("Expected PropertyName"))
{ /* ex.Message names the last good propertyName; locate the missing comma */ }

Prevention

When it happens

Trigger: A Scheme object like { "Normal": {...} "Focus": {...} } (missing comma), or { "Normal": {...}, [array] }, or a value that consumed the wrong number of tokens.

Common situations: Hand-editing JSON and dropping a comma; a templating tool emitting malformed JSON; nested object where a flat key was expected.

Related errors


AI-assisted analysis of tui-cs/Terminal.Gui@2e47b11478 (2026-08-13). Data as JSON: /api/errors/ea0d6529c247be5c. Report an issue: GitHub.