{"record":{"id":"bcdea55db1e8161e","repo":"tui-cs/Terminal.Gui","slug":"unexpected-startobject-token-when-parsing-scheme","errorCode":null,"errorMessage":"Unexpected StartObject token when parsing Scheme: {reader.TokenType}.","messagePattern":"Unexpected StartObject token when parsing Scheme: (.+?)\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Configuration/SchemeJsonConverter.cs","lineNumber":15,"sourceCode":"﻿using System.Text.Json;\nusing System.Text.Json.Serialization;\n\nnamespace Terminal.Gui.Configuration;\n\n// ReSharper disable StringLiteralTypo\n/// <summary>Implements a JSON converter for <see cref=\"Drawing.Scheme\"/>.</summary>\ninternal class SchemeJsonConverter : JsonConverter<Scheme>\n{\n    /// <inheritdoc/>\n    public override Scheme Read (ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)\n    {\n        if (reader.TokenType != JsonTokenType.StartObject)\n        {\n            throw new JsonException ($\"Unexpected StartObject token when parsing Scheme: {reader.TokenType}.\");\n        }\n\n        var scheme = new Scheme ();\n        var propertyName = string.Empty;\n\n        while (reader.Read ())\n        {\n            if (reader.TokenType == JsonTokenType.EndObject)\n            {\n                return scheme;\n            }\n\n            if (reader.TokenType != JsonTokenType.PropertyName)\n            {\n                throw new JsonException ($\"After {propertyName}: Expected PropertyName but got another token when parsing Attribute: {reader.TokenType}.\");\n            }\n\n            propertyName = reader.GetString ();","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Configuration/SchemeJsonConverter.cs#L1-L33","documentation":"SchemeJsonConverter.Read expects a JSON object (the Scheme's named VisualRole attributes). If the token at that position is not StartObject — a string, number, array, or true/false where a Scheme object was expected — it throws.","triggerScenarios":"A \"Schemes\" entry mapped to a non-object, e.g. \"Base\": \"red\" or \"Base\": 5 instead of \"Base\": { \"Normal\": { ... } }.","commonSituations":"Misunderstanding that each Scheme must be an object of role→Attribute pairs (shorthand notation is not supported); YAML flow-scalar collapse.","solutions":["Wrap the value in an object with VisualRole keys, e.g. { \"Normal\": { ... } }.","Copy a known-good Scheme object from the default theme and edit it."],"exampleFix":"// before\n\"Base\": \"Red\"\n// after\n\"Base\": { \"Normal\": { \"Foreground\": \"Red\", \"Background\": \"Black\" } }","handlingStrategy":"validation","validationCode":"using var doc = JsonDocument.Parse (configText);\nforeach (JsonProperty scheme in doc.RootElement.GetProperty (\"Schemes\").EnumerateObject ())\n{\n    if (scheme.Value.ValueKind != JsonValueKind.Object)\n        return false; // each Scheme must be an object\n}\nreturn true;","typeGuard":null,"tryCatchPattern":"try { ConfigurationManager.Apply (); }\ncatch (JsonException ex) when (ex.Message.Contains (\"Unexpected StartObject token when parsing Scheme\"))\n{ /* report which Scheme name mapped to a non-object */ }","preventionTips":["Model each Scheme as an object keyed by VisualRole names.","Diff your theme JSON against the shipped default theme before loading."],"tags":["config","json","scheme","theming"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}