{"record":{"id":"b770164f10a2fc70","repo":"microsoft/aspire","slug":"the-configuration-file-0-contains-invalid-json-1-b77016","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/Configuration/ConfigurationService.cs","lineNumber":478,"sourceCode":"        }\n        catch (UnauthorizedAccessException)\n        {\n            return new ConfigurationBuilder().Build();\n        }\n\n        if (string.IsNullOrWhiteSpace(content))\n        {\n            return new ConfigurationBuilder().Build();\n        }\n\n        JsonNode? node;\n        try\n        {\n            node = JsonNode.Parse(content, documentOptions: ConfigurationHelper.ParseOptions);\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        if (node is not JsonObject)\n        {\n            return new ConfigurationBuilder().Build();\n        }\n\n        var cleanJson = node.ToJsonString();\n        var bytes = System.Text.Encoding.UTF8.GetBytes(cleanJson);\n        return new ConfigurationBuilder()\n            .AddJsonStream(new MemoryStream(bytes))\n            .Build();\n    }\n}\n","sourceCodeStart":460,"sourceCodeEnd":495,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Configuration/ConfigurationService.cs#L460-L495","documentation":"ConfigurationService.LoadSettingsFileForReading parses a settings file's content with JsonNode.Parse and, on JsonException, rethrows as an InvalidOperationException with the same 'invalid JSON' message including the file path and parser detail. Unlike AspireConfigFile.Load this is the settings-file reader path, used when reading global/project config values.","triggerScenarios":"Reading a global or project settings/config file whose content is not valid JSON — e.g. corrupted aspire.config.json or a settings file edited by hand or another tool with a syntax error.","commonSituations":"Concurrent writers truncating the file, manual edits with syntax errors, or shell redirection appending invalid content to the config file.","solutions":["Fix the JSON syntax in the file at the reported path/position","Validate with `jq . <file>` or a JSON linter before retrying the CLI command","Restore the file from version control or delete it to regenerate defaults","Check for tools or scripts that may be writing partial/invalid content concurrently"],"exampleFix":"// before\n{ \"features\": { \"disabled\": true,, }\n// after\n{ \"features\": { \"disabled\": true } }","handlingStrategy":"validation","validationCode":"try { JsonNode.Parse(File.ReadAllText(settingsPath), documentOptions: ConfigurationHelper.ParseOptions); }\ncatch (JsonException ex) { Console.Error.WriteLine($\"{settingsPath} is invalid JSON: {ex.Message}\"); }","typeGuard":null,"tryCatchPattern":"try { var settings = await configService.LoadSettingsForReadingAsync(path); }\ncatch (InvalidOperationException ex) when (ex.InnerException is JsonException jex)\n{ Console.Error.WriteLine($\"Fix {path}: {jex.Message}\"); return 1; }","preventionTips":["Validate settings files with jq or a JSON linter before running CLI commands","Avoid concurrent writers truncating the config file","Keep config files under version control for easy rollback"],"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"}