microsoft/aspire · error · JsonException
The configuration file
Error message
The configuration file '{0}' contains invalid JSON: {1} What it means
When loading an Aspire CLI configuration file (aspire.config.json) via AspireConfigFile.Load, invalid JSON causes JsonSerializer.Deserialize to throw JsonException. The loader rethrows a JsonException with a formatted message including the file path and the underlying parser error, preserving path/line/position so users can find the syntax problem.
Solutions
- Open the file named in the error at the reported line/position and fix the JSON syntax
- Validate the file with a JSON linter or `jq . aspire.config.json`
- Remove JSON comments and trailing commas, which are not allowed in strict JSON
- Restore the file from version control and reapply changes carefully
Example fix
// before (aspire.config.json)
{ "channel": "stable", }
// after
{ "channel": "stable" } Defensive patterns
Strategy: validation
Validate before calling
try { using var doc = JsonDocument.Parse(File.ReadAllText("aspire.config.json")); }
catch (JsonException ex) { Console.Error.WriteLine($"aspire.config.json invalid: {ex.Message} at line {ex.LineNumber}"); } Try / catch
try { var cfg = AspireConfigFile.Load(path); }
catch (JsonException ex) { Console.Error.WriteLine($"Fix {path}: {ex.Message} (line {ex.LineNumber})"); return 1; } Prevention
- Run a JSON linter after every manual edit of aspire.config.json
- Never add comments or trailing commas (strict JSON only)
- Commit config files so bad edits can be reverted
- Use the CLI commands to modify config rather than hand-editing
When it happens
Trigger: Calling `config` commands (or anything that reads aspire.config.json) when the file contains malformed JSON — trailing commas, unquoted keys, unclosed braces, or BOM/encoding problems.
Common situations: Hand-editing aspire.config.json and introducing a syntax error; a tool writing a partial file; copy-paste from documentation with comments (JSON does not allow comments).
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.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- The configuration file
- The configuration file
- The configuration file
- Failed to parse JSON output into type
- Integration assets file
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/87bcf63395fb9441.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Cli/Configuration/AspireConfigFile.cs:146
/// <returns>The deserialized config, or <c>null</c> if the file does not exist.</returns>
/// <exception cref="InvalidOperationException">Thrown when the file exists but contains invalid JSON.</exception>
public static AspireConfigFile? Load(string directory)
{
var filePath = Path.Combine(directory, FileName);
if (!File.Exists(filePath))
{
return null;
}
try
{
var json = File.ReadAllText(filePath);
return JsonSerializer.Deserialize(json, JsonSourceGenerationContext.Default.AspireConfigFile)
?? new AspireConfigFile();
}
catch (JsonException ex)
{
throw new JsonException(
string.Format(CultureInfo.CurrentCulture, ErrorStrings.InvalidJsonInConfigFile, filePath, ex.Message),
ex.Path, ex.LineNumber, ex.BytePositionInLine, ex);
}
}
/// <summary>
/// Saves aspire.config.json to the specified directory.
/// Uses relaxed JSON escaping so non-ASCII characters (CJK, etc.) are preserved as-is.
/// </summary>
public void Save(string directory)
{
Directory.CreateDirectory(directory);
var filePath = Path.Combine(directory, FileName);
var json = JsonSerializer.Serialize(this, JsonSourceGenerationContext.RelaxedEscaping.AspireConfigFile);
File.WriteAllText(filePath, json);
}
/// <summary>View on GitHub (pinned to 25830f84bd)