{"record":{"id":"791abe7679bea7fa","repo":"tui-cs/Terminal.Gui","slug":"unexpected-startobject-token-when-parsing-attribut","errorCode":null,"errorMessage":"Unexpected StartObject token when parsing Attribute: {reader.TokenType}.","messagePattern":"Unexpected StartObject token when parsing Attribute: (.+?)\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Configuration/AttributeJsonConverter.cs","lineNumber":29,"sourceCode":"    /// <summary></summary>\n    public static AttributeJsonConverter Instance\n    {\n        get\n        {\n            if (_instance is null)\n            {\n                _instance = new AttributeJsonConverter ();\n            }\n\n            return _instance;\n        }\n    }\n\n    public override Attribute 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 Attribute: {reader.TokenType}.\");\n        }\n\n        var attribute = new Attribute ();\n        Color? foreground = null;\n        Color? background = null;\n        TextStyle? style = null;\n\n        string propertyName = string.Empty;\n\n        while (reader.Read ())\n        {\n            if (reader.TokenType == JsonTokenType.EndObject)\n            {\n                if (foreground is null || background is null)\n                {\n                    throw new JsonException ($\"{propertyName}: Both Foreground and Background colors must be provided.\");\n                }\n","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Configuration/AttributeJsonConverter.cs#L11-L47","documentation":"Thrown as JsonException by AttributeJsonConverter.Read when the reader is not positioned on a StartObject token. An Attribute in Terminal.Gui config JSON must be a JSON object like {\"Foreground\":..., \"Background\":...}. Supplying a bare string, number, array, or a pre-consumed token produces this error with the offending TokenType in the message.","triggerScenarios":"Writing a Scheme/Attribute in a theme JSON config file as a shorthand string (e.g. \"red\") instead of an object; nesting Attribute where a different type was expected; a malformed config file from a manual edit or a bad config generator.","commonSituations":"Hand-editing a Terminal.Gui theme/config JSON and using the wrong shape for an attribute; migrating an old config format that used string color names; tooling that emits the wrong JSON node type for color attributes.","solutions":["Ensure every Attribute value in config JSON is an object with at least Foreground and Background keys.","Validate the config JSON against the expected schema before applying it with ConfigurationManager.","Use the format { \"Foreground\": { ... }, \"Background\": { ... } } and optionally \"Style\": \"Bold\"."],"exampleFix":"// before (config.json)\n\"Normal\": \"red\"\n\n// after\n\"Normal\": { \"Foreground\": \"red\", \"Background\": \"black\" }","handlingStrategy":"validation","validationCode":"// Validate config JSON before applying:\n// every Attribute must be a JSON object, not a scalar or array.\nvar doc = JsonDocument.Parse (configText);\nforeach (var attr in /* locate Attribute nodes */)\n{\n    if (attr.ValueKind != JsonValueKind.Object)\n    {\n        throw new InvalidOperationException ($\"Attribute must be an object, got {attr.ValueKind}\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    ConfigurationManager.Load (configText);\n}\ncatch (JsonException ex)\n{\n    Logging.Error ($\"Bad config JSON for Attribute: {ex.Message}\");\n}","preventionTips":["Always write Attribute values as JSON objects with Foreground/Background keys.","Validate theme JSON with a schema or test-parse before applying.","Avoid shorthand string color values for Attribute nodes."],"tags":["config","json","serialization","theme"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}