tui-cs/Terminal.Gui · error · JsonException
{propertyName}: Expected an array of modifiers, but got "{re
Error message
{propertyName}: Expected an array of modifiers, but got "{reader.TokenType}". What it means
Thrown by KeyCodeJsonConverter.Read (KeyCodeJsonConverter.cs:100-105) when the "Modifiers" property value is not a JSON StartArray token. Modifiers must be an array of strings (["Ctrl", "Shift"]); providing a single string "Ctrl" or an object triggers this.
Source
Thrown at Terminal.Gui/Configuration/KeyCodeJsonConverter.cs:102
{
break;
}
string mod = reader.GetString ();
try
{
modifiers.Add (modifierDict [mod]);
}
catch (KeyNotFoundException e)
{
throw new JsonException ($"{propertyName}: \"{mod}\" is not a valid modifier.", e);
}
}
}
else
{
throw new JsonException (
$"{propertyName}: Expected an array of modifiers, but got \"{reader.TokenType}\"."
);
}
break;
default:
throw new JsonException ($"{propertyName}: Unexpected Key property.");
}
}
}
foreach (KeyCode modifier in modifiers)
{
key |= modifier;
}
return key;View on GitHub (pinned to 2e47b11478)
Solutions
- Always write Modifiers as a JSON array, even for a single modifier: ["Ctrl"].
- For no modifiers, use an empty array [] or omit the Modifiers property.
- Validate the Modifiers property is an array type before serializing config.
Example fix
// before
{ "Key": "A", "Modifiers": "Ctrl" }
// after
{ "Key": "A", "Modifiers": ["Ctrl"] } Defensive patterns
Strategy: validation
Validate before calling
using System.Text.Json;
static bool ModifiersIsArray (string json, string propertyName)
{
using JsonDocument doc = JsonDocument.Parse (json);
// locate the property; illustrative
return true;
}
// Ensure "Modifiers" is a JSON array in the raw config. Type guard
static bool IsModifiersArray (JsonElement el) => el.ValueKind == JsonValueKind.Array;
Try / catch
try
{
ConfigurationManager.Load (configJson);
}
catch (JsonException ex) when (ex.Message.Contains ("Expected an array of modifiers"))
{
// "Modifiers" was a scalar/object. Rewrite it as ["..."] and reload.
} Prevention
- Always write Modifiers as a JSON array, even for a single modifier.
- Use [] or omit Modifiers for no modifiers.
- Validate the Modifiers property is an array before serializing.
- Do not let tooling collapse single-element arrays to scalars.
When it happens
Trigger: Config JSON has "Modifiers": "Ctrl" (scalar string) or "Modifiers": { ... } instead of "Modifiers": ["Ctrl"].
Common situations: User writes a single modifier as a bare string for brevity. Tooling collapses single-element arrays to scalars. Copy-paste from a format that uses comma-separated strings.
Related errors
- {propertyName}: "{mod}" is not a valid modifier.
- Expected start of array for Key[].
- Expected string token in Key array, got {reader.TokenType}.
- {propertyName}: "{reader.GetString ()}" is not a valid Key.
- {propertyName}: Error parsing Key value: {ioe.Message}
AI-assisted analysis of tui-cs/Terminal.Gui@2e47b11478 (2026-08-13).
Data as JSON: /api/errors/d4a26ccfed91748a.
Report an issue: GitHub.