{"record":{"id":"36e8c651fc76614d","repo":"tui-cs/Terminal.Gui","slug":"expected-string-token-in-mouseflags-array-got-re","errorCode":null,"errorMessage":"Expected string token in MouseFlags array, got {reader.TokenType}.","messagePattern":"Expected string token in MouseFlags array, got (.+?)\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Configuration/MouseFlagsArrayJsonConverter.cs","lineNumber":36,"sourceCode":"        }\n\n        if (reader.TokenType != JsonTokenType.StartArray)\n        {\n            throw new JsonException (\"Expected start of array for MouseFlags[].\");\n        }\n\n        List<MouseFlags> mouseFlagsList = [];\n\n        while (reader.Read ())\n        {\n            if (reader.TokenType == JsonTokenType.EndArray)\n            {\n                return mouseFlagsList.ToArray ();\n            }\n\n            if (reader.TokenType != JsonTokenType.String)\n            {\n                throw new JsonException ($\"Expected string token in MouseFlags array, got {reader.TokenType}.\");\n            }\n\n            string mouseFlagsString = reader.GetString ()!;\n            mouseFlagsString = mouseFlagsString.Replace (\"+\", \", \").Replace (\"|\", \", \");\n\n            mouseFlagsList.Add (Enum.TryParse (mouseFlagsString, true, out MouseFlags mouseFlags) ? mouseFlags : MouseFlags.None);\n        }\n\n        throw new JsonException (\"Unexpected end of JSON while reading MouseFlags array.\");\n    }\n\n    /// <inheritdoc/>\n    public override void Write (Utf8JsonWriter writer, MouseFlags []? value, JsonSerializerOptions options)\n    {\n        if (value is null)\n        {\n            writer.WriteNullValue ();\n","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Configuration/MouseFlagsArrayJsonConverter.cs#L18-L54","documentation":"Thrown by MouseFlagsArrayJsonConverter.Read (MouseFlagsArrayJsonConverter.cs:34-37) inside the array loop when an element token is not a String. Each element of a MouseFlags[] JSON array must be a string parseable as MouseFlags (with '+' or '|' split into combined flags). A number, boolean, object, or nested array element triggers this.","triggerScenarios":"A MouseFlags[] JSON array contains a non-string element, e.g. [\"Button1Clicked\", 1] (numeric flag value) or [\"Button1Clicked\", {\"Flags\":\"Button2Clicked\"}].","commonSituations":"User writes a numeric MouseFlags enum value directly. Tooling emits typed numbers. Mixing formats.","solutions":["Make every element a string token using MouseFlags enum names: \"Button1Clicked\", \"WheeledUp\", \"Button1Clicked+Shift\", etc.","Combine flags with '+' or '|' inside the string: \"Button1Clicked+Shift\" is accepted (the converter splits on '+' and '|').","Convert any numeric flag values to their MouseFlags enum name strings before writing config.","Validate each array element is a JSON string."],"exampleFix":"// before\n\"Click\": [\"Button1Clicked\", 0x100000]\n\n// after\n\"Click\": [\"Button1Clicked\", \"Button1Clicked+Shift\"]","handlingStrategy":"validation","validationCode":"using System.Text.Json;\n\nstatic bool MouseFlagsElementsAreStrings (string json, string propertyName)\n{\n    using JsonDocument doc = JsonDocument.Parse (json);\n    if (!doc.RootElement.TryGetProperty (propertyName, out JsonElement el)) return true;\n    if (el.ValueKind != JsonValueKind.Array) return false;\n    foreach (JsonElement item in el.EnumerateArray ())\n    {\n        if (item.ValueKind != JsonValueKind.String) return false;\n    }\n    return true;\n}","typeGuard":"static bool IsMouseFlagsArrayElement (JsonElement el) => el.ValueKind == JsonValueKind.String;","tryCatchPattern":"try\n{\n    ConfigurationManager.Load (configJson);\n}\ncatch (JsonException ex) when (ex.Message.Contains (\"Expected string token in MouseFlags array\"))\n{\n    // Find the non-string element and replace it with its MouseFlags.ToString() form.\n}","preventionTips":["Write every MouseFlags[] element as a string using MouseFlags enum names.","Combine flags with '+' or '|' inside the string (\"Button1Clicked+Shift\").","Convert numeric flag values to enum names before writing config.","Validate each array element is a string before serializing."],"tags":["json","configuration","mouse","mousebindings","serialization"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}