{"record":{"id":"e925bf764ca78964","repo":"microsoft/aspire","slug":"the-configuration-file-0-contains-malformed-json-please-fix","errorCode":null,"errorMessage":"The configuration file '{0}' contains malformed JSON. Please fix the file manually and re-run the command.","messagePattern":"The configuration file '(.+?)' contains malformed JSON\\. Please fix the file manually and re-run the command\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/Agents/McpConfigFileHelper.cs","lineNumber":90,"sourceCode":"        {\n            return new JsonObject();\n        }\n\n        var content = await File.ReadAllTextAsync(configFilePath, cancellationToken);\n\n        if (preprocessContent is not null)\n        {\n            content = preprocessContent(content);\n        }\n\n        JsonNode? root;\n        try\n        {\n            root = JsonNode.Parse(content);\n        }\n        catch (JsonException ex)\n        {\n            throw new InvalidOperationException(\n                string.Format(CultureInfo.CurrentCulture, AgentCommandStrings.MalformedConfigFileError, configFilePath), ex);\n        }\n\n        return root as JsonObject\n            ?? throw new InvalidOperationException(\n                string.Format(CultureInfo.CurrentCulture, ErrorStrings.ConfigurationFileMustBeJsonObject, configFilePath));\n    }\n}\n","sourceCodeStart":72,"sourceCodeEnd":99,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Agents/McpConfigFileHelper.cs#L72-L99","documentation":"McpConfigFileHelper.ReadConfigAsync parses an MCP agent configuration file (e.g. mcp.json) with JsonNode.Parse. This error is thrown when the file contains syntactically invalid JSON, with the original JsonException attached as the inner exception. The CLI refuses to proceed so it never corrupts or guesses at a broken config, and asks the user to repair the file by hand.","triggerScenarios":"Thrown when JsonNode.Parse throws JsonException while parsing the contents of the config file at configFilePath — trailing commas, comments in strict JSON, truncated writes, BOM/encoding issues, or hand-edited syntax errors.","commonSituations":"Manually editing mcp.json and leaving a trailing comma or unquoted key; a previous crashed command left a truncated file; merging changes with a tool that emitted JSON5/JSONC; copy-pasting config with smart quotes.","solutions":["Open the file named in the message and fix the JSON syntax (check trailing commas, quotes, and braces) — the inner JsonException line/position pinpoints it.","Validate the file with a JSON linter or `jq . <file>` before re-running the command.","If unsure of the correct content, delete or rename the broken file and let the CLI regenerate a fresh one, then re-apply your agent entries.","Restore the file from backup or source control if it was accidentally corrupted."],"exampleFix":"// before\n{\n  \"mcpServers\": { \"fs\": { \"command\": \"npx\", }\n}\n// after\n{\n  \"mcpServers\": { \"fs\": { \"command\": \"npx\" } }\n}","handlingStrategy":"validation","validationCode":"if (!System.Text.Json.JsonDocument.TryParse(File.ReadAllText(mcpJsonPath), out _))\n{\n    // fix JSON syntax before invoking the CLI command\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    await command.ExecuteAsync();\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"contains malformed JSON\"))\n{\n    // surface ex.InnerException (JsonException) position info to the user\n}","preventionTips":["Validate mcp.json with a JSON linter or `jq . file` after every hand edit.","Do not hand-write trailing commas or comments in strict-JSON config files.","Let the CLI regenerate config skeletons instead of editing from scratch."],"tags":["json","config","parse-error","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"}