{"record":{"id":"ecd6ad67bef1d94d","repo":"tui-cs/Terminal.Gui","slug":"unexpected-token-when-parsing-color-reader-token","errorCode":null,"errorMessage":"Unexpected token when parsing Color: {reader.TokenType}","messagePattern":"Unexpected token when parsing Color: (.+?)","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Configuration/ColorJsonConverter.cs","lineNumber":55,"sourceCode":"        if (reader.TokenType == JsonTokenType.String)\n        {\n            // Get the color string\n            ReadOnlySpan<char> colorString = reader.GetString ();\n\n            if (ColorStrings.TryParseNamedColor (colorString, out Color namedColor))\n            {\n                return namedColor;\n            }\n\n            if (Color.TryParse (colorString, null, out Color parsedColor))\n            {\n                return parsedColor;\n            }\n\n            throw new JsonException ($\"Unexpected color name: {colorString}.\");\n        }\n\n        throw new JsonException ($\"Unexpected token when parsing Color: {reader.TokenType}\");\n    }\n\n    public override void Write (Utf8JsonWriter writer, Color value, JsonSerializerOptions options)\n    {\n        writer.WriteStringValue (value.ToString ());\n    }\n}\n","sourceCodeStart":37,"sourceCodeEnd":63,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Configuration/ColorJsonConverter.cs#L37-L63","documentation":"Thrown by ColorJsonConverter.Read when the JSON token for a Color value is not a string at all (e.g. Number, StartObject, True, Null). Color is serialized and expected as a string token; any other token type is rejected before parsing is attempted.","triggerScenarios":"\"Foreground\": 255, or \"Foreground\": { \"R\": 255 }, or \"Foreground\": null, or \"Foreground\": [255,0,0].","commonSituations":"An exporter that serializes Color as a numeric code or RGB object; a config that uses null to mean \"default\"; copy-paste of an object form from a different theming system.","solutions":["Provide the color as a JSON string (\"Red\", \"#FF0000\", \"rgb(255,0,0)\").","If your tool emits objects/numbers, transform them to the string form before loading.","Remove the null entry — omit the key entirely instead of setting null."],"exampleFix":"// before\n\"Background\": 0\n// after\n\"Background\": \"Black\"","handlingStrategy":"validation","validationCode":"if (el.ValueKind != JsonValueKind.String)\n    throw new FormatException ($\"Color must be a string token, was {el.ValueKind}\");","typeGuard":"static bool IsColorToken (JsonElement e) => e.ValueKind == JsonValueKind.String;","tryCatchPattern":"try { ConfigurationManager.Apply (); }\ncatch (JsonException ex) when (ex.Message.Contains (\"Unexpected token when parsing Color\"))\n{ /* convert the non-string color to a string form */ }","preventionTips":["Always serialize Color as a string.","Reject object/number forms at the config-authoring layer."],"tags":["configuration","json","theming","color"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}