{"record":{"id":"7fd8b6f166408528","repo":"SubtitleEdit/subtitleedit","slug":"failed-to-parse-multiple-replace-json-at-path","errorCode":null,"errorMessage":"Failed to parse multiple-replace JSON at {path}: {ex.Message}","messagePattern":"Failed to parse multiple-replace JSON at (.+?): (.+?)","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"error","filePath":"src/seconv/Core/MultipleReplaceLoader.cs","lineNumber":130,"sourceCode":"                    rules.Add(rule);\n                }\n            }\n        }\n\n        return rules;\n    }\n\n    private static CategoryImportExport ParseJson(string content, string path)\n    {\n        try\n        {\n            var item = System.Text.Json.JsonSerializer.Deserialize<CategoryImportExport>(content,\n                new System.Text.Json.JsonSerializerOptions { PropertyNameCaseInsensitive = true });\n            return item ?? new CategoryImportExport();\n        }\n        catch (Exception ex)\n        {\n            throw new InvalidDataException($\"Failed to parse multiple-replace JSON at {path}: {ex.Message}\", ex);\n        }\n    }\n\n    // Flattens the SE5 category/rule shape (shared by the .template JSON and the CSV) into active\n    // rules, mapping the UI's MultipleReplaceType names to the XML SearchType names the apply loop\n    // expects: CaseInsensitive -> Normal, others by name.\n    private static List<Rule> LoadCategoryItemRules(CategoryImportExport item)\n    {\n        var rules = new List<Rule>();\n        if (item.Categories == null)\n        {\n            return rules;\n        }\n\n        foreach (var category in item.Categories)\n        {\n            if (category.Rules == null)\n            {","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/seconv/Core/MultipleReplaceLoader.cs#L112-L148","documentation":"Wrapped exception thrown by MultipleReplaceLoader.ParseJson when System.Text.Json.JsonSerializer.Deserialize<CategoryImportExport> fails on the multiple-replace file content. The file was read successfully but is not valid JSON or does not map to the CategoryImportExport schema (the SE5 category/rule shape used by .template and .csv exports). The original exception is preserved as InnerException of an InvalidDataException with the path and original message.","triggerScenarios":"The multiple-replace file is selected as JSON (by .json/.template extension or content starting with '{') but is malformed JSON (trailing commas, unquoted keys, truncated), or has a valid JSON structure that doesn't match the CategoryImportExport type.","commonSituations":"Hand-editing the JSON and introducing a syntax error; a file exported by a different version of SE with a changed schema; truncated download/copy; mixing .json with a CSV body that starts with '{'.","solutions":["Validate the JSON with a linter (e.g. `python -m json.tool file.json`) to find the syntax error.","If the file is actually XML or CSV, rename it with the correct extension (.xml/.csv) so the loader picks the right parser.","Re-export from the SE GUI (Tools > Multiple replace > export as .template) to get a valid file."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { var rules = MultipleReplaceLoader.LoadRules(path); }\ncatch (InvalidDataException ex) when (ex.Message.Contains(\"Failed to parse multiple-replace JSON\"))\n{\n    // ex.InnerException has the JsonException with line/byte position\n    var jsonError = ex.InnerException;\n    // Report JSON parse error, suggest re-export or fix\n}","preventionTips":["Validate JSON files with a JSON linter before using them.","Use the correct file extension (.json/.template) so the loader picks the right parser.","Re-export from the SE GUI to get schema-valid files rather than hand-editing JSON."],"tags":["multiple-replace","json","parse-failure","validation","subtitles"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}