{"record":{"id":"98fe9437d767edac","repo":"microsoft/aspire","slug":"the-configuration-file-0-contains-invalid-json-1-98fe94","errorCode":null,"errorMessage":"The configuration file '{0}' contains invalid JSON: {1}","messagePattern":"The configuration file '(.+?)' contains invalid JSON: (.+?)","errorType":"validation","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/Utils/ConfigurationHelper.cs","lineNumber":277,"sourceCode":"\n        // Pre-process the file to handle comments and trailing commas.\n        // Microsoft.Extensions.Configuration.Json doesn't support JSON comments,\n        // so we parse with comment support and load the clean JSON via stream.\n        try\n        {\n            var content = File.ReadAllText(filePath);\n            var node = JsonNode.Parse(content, documentOptions: ParseOptions);\n            if (node is not null)\n            {\n                var cleanJson = node.ToJsonString(new JsonSerializerOptions { WriteIndented = true });\n                var bytes = System.Text.Encoding.UTF8.GetBytes(cleanJson);\n                configuration.AddJsonStream(new MemoryStream(bytes));\n                return;\n            }\n        }\n        catch (JsonException ex)\n        {\n            throw new InvalidOperationException(\n                string.Format(CultureInfo.CurrentCulture, ErrorStrings.InvalidJsonInConfigFile, filePath, ex.Message),\n                ex);\n        }\n\n        configuration.AddJsonFile(filePath, optional: true);\n    }\n\n    /// <summary>\n    /// Normalizes a settings file by converting flat colon-separated keys to nested JSON objects.\n    /// </summary>\n    internal static bool TryNormalizeSettingsFile(string filePath)\n    {\n        try\n        {\n            var content = File.ReadAllText(filePath);\n\n            if (string.IsNullOrWhiteSpace(content))\n            {","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Utils/ConfigurationHelper.cs#L259-L295","documentation":"ConfigurationHelper.AddSettingsFile loads a user settings file into the CLI configuration by parsing it as JSON. If System.Text.Json raises a JsonException while reading the file, the helper wraps it in an InvalidOperationException that includes the file path and the parser's message, so users know which settings file is malformed rather than getting a bare parse error.","triggerScenarios":"Calling CLI commands that register settings files (via RegisterSettingsFile) when a settings file on disk (e.g. .aspire/settings.json) contains syntactically invalid JSON - trailing commas, unquoted keys, comments where not allowed, truncated edits.","commonSituations":"Hand-editing aspire settings.json and leaving a trailing comma or missing brace, a merge conflict marker left inside the file, an editor writing BOM/encoding issues, or an interrupted write leaving a truncated file.","solutions":["Open the settings file named in the message and fix the JSON at the position given by the parser message (e.g. remove trailing commas, close braces).","Validate the file with a JSON linter or `cat file | python -m json.tool` before rerunning the command.","If you cannot repair it, delete or restore the settings file and let the CLI regenerate defaults; re-apply settings carefully.","Restore from git or a backup if the file was broken by a merge conflict."],"exampleFix":"// before (.aspire/settings.json)\n{\n  \"features\": { \"updateNotificationsEnabled\": true, },\n// after\n{\n  \"features\": { \"updateNotificationsEnabled\": true }\n}","handlingStrategy":"validation","validationCode":"try { using var doc = JsonDocument.Parse(File.ReadAllText(settingsPath)); }\ncatch (JsonException ex) { Console.WriteLine($\"{settingsPath} has invalid JSON: {ex.Message}\"); }","typeGuard":null,"tryCatchPattern":"try { /* run aspire command */ }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"invalid JSON\")) { Console.Error.WriteLine(ex.Message); /* point user at the file/offset */ }","preventionTips":["Edit settings files in an editor with JSON validation/schema support.","Run a JSON linter after hand edits and after resolving merge conflicts.","Keep settings files in git so broken edits can be reverted."],"tags":["json","configuration","cli","parse-error"],"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"}