{"record":{"id":"87bcf63395fb9441","repo":"microsoft/aspire","slug":"the-configuration-file-0-contains-invalid-json-1","errorCode":null,"errorMessage":"The configuration file '{0}' contains invalid JSON: {1}","messagePattern":"The configuration file '(.+?)' contains invalid JSON: (.+?)","errorType":"validation","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/Configuration/AspireConfigFile.cs","lineNumber":146,"sourceCode":"    /// <returns>The deserialized config, or <c>null</c> if the file does not exist.</returns>\n    /// <exception cref=\"InvalidOperationException\">Thrown when the file exists but contains invalid JSON.</exception>\n    public static AspireConfigFile? Load(string directory)\n    {\n        var filePath = Path.Combine(directory, FileName);\n        if (!File.Exists(filePath))\n        {\n            return null;\n        }\n\n        try\n        {\n            var json = File.ReadAllText(filePath);\n            return JsonSerializer.Deserialize(json, JsonSourceGenerationContext.Default.AspireConfigFile)\n                ?? new AspireConfigFile();\n        }\n        catch (JsonException ex)\n        {\n            throw new JsonException(\n                string.Format(CultureInfo.CurrentCulture, ErrorStrings.InvalidJsonInConfigFile, filePath, ex.Message),\n                ex.Path, ex.LineNumber, ex.BytePositionInLine, ex);\n        }\n    }\n\n    /// <summary>\n    /// Saves aspire.config.json to the specified directory.\n    /// Uses relaxed JSON escaping so non-ASCII characters (CJK, etc.) are preserved as-is.\n    /// </summary>\n    public void Save(string directory)\n    {\n        Directory.CreateDirectory(directory);\n        var filePath = Path.Combine(directory, FileName);\n        var json = JsonSerializer.Serialize(this, JsonSourceGenerationContext.RelaxedEscaping.AspireConfigFile);\n        File.WriteAllText(filePath, json);\n    }\n\n    /// <summary>","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Configuration/AspireConfigFile.cs#L128-L164","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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"],"exampleFix":"// before (aspire.config.json)\n{ \"channel\": \"stable\", }\n// after\n{ \"channel\": \"stable\" }","handlingStrategy":"validation","validationCode":"try { using var doc = JsonDocument.Parse(File.ReadAllText(\"aspire.config.json\")); }\ncatch (JsonException ex) { Console.Error.WriteLine($\"aspire.config.json invalid: {ex.Message} at line {ex.LineNumber}\"); }","typeGuard":null,"tryCatchPattern":"try { var cfg = AspireConfigFile.Load(path); }\ncatch (JsonException ex) { Console.Error.WriteLine($\"Fix {path}: {ex.Message} (line {ex.LineNumber})\"); return 1; }","preventionTips":["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"],"tags":["config","json","cli"],"backgroundTag":"json-parse-error","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}