{"record":{"id":"da7f79189619e801","repo":"JamesNK/Newtonsoft.Json","slug":"unknown-escape-character","errorCode":null,"errorMessage":"Unknown escape character: \\","messagePattern":"Unknown escape character: \\\\","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Linq/JsonPath/JPath.cs","lineNumber":688,"sourceCode":"                            resolvedChar = '\\t';\n                            break;\n                        case 'n':\n                            resolvedChar = '\\n';\n                            break;\n                        case 'f':\n                            resolvedChar = '\\f';\n                            break;\n                        case 'r':\n                            resolvedChar = '\\r';\n                            break;\n                        case '\\\\':\n                        case '\"':\n                        case '\\'':\n                        case '/':\n                            resolvedChar = currentChar;\n                            break;\n                        default:\n                            throw new JsonException(@\"Unknown escape character: \\\" + currentChar);\n                    }\n\n                    sb.Append(resolvedChar);\n\n                    _currentIndex++;\n                }\n                else if (currentChar == '\\'')\n                {\n                    _currentIndex++;\n                    return sb.ToString();\n                }\n                else\n                {\n                    _currentIndex++;\n                    sb.Append(currentChar);\n                }\n            }\n","sourceCodeStart":670,"sourceCodeEnd":706,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Linq/JsonPath/JPath.cs#L670-L706","documentation":"Thrown by ReadQuotedString when a backslash escape inside a single-quoted JSONPath string literal is followed by a character that is not one of the recognized escape codes (b, t, n, f, r, backslash, double-quote, single-quote, forward-slash). Only that fixed set of escapes is supported inside JSONPath quoted strings.","triggerScenarios":"A quoted field name or string value containing an unsupported escape. Example: token.SelectTokens(\"$['foo\\\\x']\") or a query like \"$..[?(@.name == 'a\\\\q')]\" where \\\\x / \\\\q are not valid escapes.","commonSituations":"Forwarding user text containing Windows file paths or regex into a JSONPath without sanitization; assuming JSONPath supports the same escapes as C# or JSON verbatim strings (e.g. \\uXXXX is not supported here); constructing paths from URIs that contain %2F style sequences.","solutions":["Replace unsupported escapes: use \\\\uXXXX via JSON string rules outside JSONPath, or escape the raw characters differently.","For literal backslashes use the supported \\\\\\\\ escape (backslash-backslash).","Sanitize/escape user-supplied text before interpolating it into a JSONPath quoted string."],"exampleFix":"// before\ntoken.SelectTokens(\"$['C:\\\\new']\");\n// after\ntoken.SelectTokens(\"$['C:\\\\\\\\new']\");","handlingStrategy":"validation","validationCode":"static string EscapeForJsonPath(string value)\n{\n    return value.Replace(\"\\\\\", \"\\\\\\\\\").Replace(\"'\", \"\\\\'\");\n}","typeGuard":null,"tryCatchPattern":"try { token.SelectTokens($\"$['{field}']\").ToList(); }\ncatch (JsonException ex) when (ex.Message.StartsWith(\"Unknown escape character\"))\n{ /* field contained an unsupported escape; sanitize and retry */ }","preventionTips":["Sanitize interpolated text: escape backslash and single-quote.","Avoid \\uXXXX inside JSONPath quoted strings; it is not supported here."],"tags":["jsonpath","json","parsing","escaping","jpath"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}