{"record":{"id":"a22fcc8d4f3d307e","repo":"tui-cs/Terminal.Gui","slug":"propertyname-unexpected-startobject-token-when","errorCode":null,"errorMessage":"{propertyName}: Unexpected StartObject token when parsing Key: {reader.TokenType}.","messagePattern":"(.+?): Unexpected StartObject token when parsing Key: (.+?)\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Configuration/KeyCodeJsonConverter.cs","lineNumber":123,"sourceCode":"                            }\n\n                            break;\n\n                        default:\n                            throw new JsonException ($\"{propertyName}: Unexpected Key property.\");\n                    }\n                }\n            }\n\n            foreach (KeyCode modifier in modifiers)\n            {\n                key |= modifier;\n            }\n\n            return key;\n        }\n\n        throw new JsonException ($\"{propertyName}: Unexpected StartObject token when parsing Key: {reader.TokenType}.\");\n    }\n\n    public override void Write (Utf8JsonWriter writer, KeyCode value, JsonSerializerOptions options)\n    {\n        writer.WriteStartObject ();\n\n        var keyName = (value & ~KeyCode.CtrlMask & ~KeyCode.ShiftMask & ~KeyCode.AltMask).ToString ();\n\n        writer.WriteString (\"Key\", keyName);\n\n        Dictionary<string, KeyCode> modifierDict = new ()\n        {\n            { \"Shift\", KeyCode.ShiftMask }, { \"Ctrl\", KeyCode.CtrlMask }, { \"Alt\", KeyCode.AltMask }\n        };\n\n        List<string> modifiers = new ();\n\n        foreach (KeyValuePair<string, KeyCode> pair in modifierDict)","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Configuration/KeyCodeJsonConverter.cs#L105-L141","documentation":"Thrown by KeyCodeJsonConverter.Read (KeyCodeJsonConverter.cs:123) when the initial token is not StartObject. The converter expects a Key to be a JSON object {\"Key\": ..., \"Modifiers\": [...]}. Supplying a bare string, number, or array for a KeyCode-typed property hits this terminal throw after the if-block.","triggerScenarios":"A KeyCode-typed config property is given as a scalar (e.g. \"Accept\": \"Enter\" or \"Accept\": 13) instead of the object form {\"Key\":\"Enter\"}. The reader is not positioned on a StartObject token.","commonSituations":"User writes the short string form where the object KeyCode form is expected (note: Key[] arrays use strings, but a single KeyCode property uses the object form). Tooling emits scalars. Mixing up the two Key serialization formats (object KeyCode vs string-array Key[]).","solutions":["Write KeyCode properties as JSON objects: {\"Key\":\"Enter\"} or {\"Key\":\"A\",\"Modifiers\":[\"Ctrl\"]}.","If the property is actually Key[] (array), use the string-array form and ensure the property type is Key[], not KeyCode.","Confirm which converter applies to the property type: KeyCode uses the object form, Key[] uses string arrays.","Validate the token type is StartObject before deserialization."],"exampleFix":"// before (KeyCode property given a scalar)\n\"Accept\": \"Enter\"\n\n// after (KeyCode property as object)\n\"Accept\": { \"Key\": \"Enter\" }","handlingStrategy":"validation","validationCode":"using System.Text.Json;\n\nstatic bool KeyPropertyIsObject (string json, string propertyName)\n{\n    using JsonDocument doc = JsonDocument.Parse (json);\n    if (!doc.RootElement.TryGetProperty (propertyName, out JsonElement el)) return true;\n    return el.ValueKind == JsonValueKind.Object;\n}\n\nif (!KeyPropertyIsObject (configJson, \"Accept\"))\n{\n    // wrap the scalar into {\"Key\": ...} before loading\n}","typeGuard":"static bool IsKeyCodeObject (JsonElement el) => el.ValueKind == JsonValueKind.Object;","tryCatchPattern":"try\n{\n    ConfigurationManager.Load (configJson);\n}\ncatch (JsonException ex) when (ex.Message.Contains (\"Unexpected StartObject token when parsing Key\"))\n{\n    // A KeyCode property was given a scalar. Rewrite it as {\"Key\": ...} and reload.\n}","preventionTips":["Write KeyCode properties as JSON objects {\"Key\": \"Enter\"}.","Confirm whether the property type is KeyCode (object form) or Key[] (string array form).","Do not mix the two Key serialization formats.","Use a Terminal.Gui-serialized config as the canonical reference."],"tags":["json","configuration","keybindings","key","schema","serialization"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}