microsoft/aspire · error · JsonException
Expected PropertyName, got
Error message
Expected PropertyName, got {reader.TokenType} What it means
While iterating the members of a dictionary-shaped JSON object, the converter expects each token after StartObject (or after a value) to be a PropertyName; any other token throws JsonException. This indicates malformed or structurally unexpected JSON rather than a value-level problem.
Solutions
- Validate the JSON file with a JSON linter/parser to find the structural error near the reported property.
- Repair the object so every entry is "name": value pairs inside the braces.
- If generated, fix the generator to emit a plain JSON object for this property.
Example fix
// before (array where object properties expected)
"featureFlags": ["A", "B"]
// after
"featureFlags": { "A": true, "B": false } Defensive patterns
Strategy: try-catch
Validate before calling
try { using var _ = JsonDocument.Parse(json); } // full structural validation first
catch (JsonException ex) { throw new FormatException($"Malformed JSON: {ex.Message}"); } Try / catch
try
{
var config = JsonSerializer.Deserialize<MyConfig>(json, options);
}
catch (JsonException ex) when (ex.Message.StartsWith("Expected PropertyName"))
{
logger.LogError(ex, "Malformed JSON object structure in configuration.");
} Prevention
- Run JSON through a linter/parser after every manual edit.
- Avoid hand-editing generated config sections.
- Keep config files under source control so corruption is diffable.
When it happens
Trigger: Malformed JSON where an array or scalar appears where a property name should be; JSON that closes the object then contains trailing tokens reaching the converter loop; programmatically constructed reader sequences.
Common situations: Hand-crafted or machine-generated JSON with structural mistakes; interleaved edits corrupting a config file; a serializer upstream writing an unexpected shape for this section.
Understand the failure class
Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.
Related errors
- Cannot convert string
- Error deserializing GenAI message content. Error description
- Expected a non-empty Kubernetes MicroTime value.
- Expected a string token for Kubernetes MicroTime but found
- Expected StartObject, got
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/166238bb65f96415.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Cli/Configuration/FlexibleBooleanDictionaryConverter.cs:39
}
if (reader.TokenType != JsonTokenType.StartObject)
{
throw new JsonException($"Expected StartObject, got {reader.TokenType}");
}
var dictionary = new Dictionary<string, bool>();
while (reader.Read())
{
if (reader.TokenType == JsonTokenType.EndObject)
{
return dictionary;
}
if (reader.TokenType != JsonTokenType.PropertyName)
{
throw new JsonException($"Expected PropertyName, got {reader.TokenType}");
}
var key = reader.GetString() ?? throw new JsonException("Property name cannot be null");
reader.Read();
bool value = reader.TokenType switch
{
JsonTokenType.True => true,
JsonTokenType.False => false,
JsonTokenType.String => ParseBooleanString(reader.GetString(), key),
_ => throw new JsonException($"Cannot convert {reader.TokenType} to boolean for key '{key}'")
};
dictionary[key] = value;
}
throw new JsonException("Unexpected end of JSON");View on GitHub (pinned to 25830f84bd)