{"record":{"id":"74b55f046d973079","repo":"JamesNK/Newtonsoft.Json","slug":"path-ended-with-an-open-string","errorCode":null,"errorMessage":"Path ended with an open string.","messagePattern":"Path ended with an open string\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Linq/JsonPath/JPath.cs","lineNumber":707,"sourceCode":"                    }\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\n            throw new JsonException(\"Path ended with an open string.\");\n        }\n\n        private string ReadRegexString()\n        {\n            int startIndex = _currentIndex;\n\n            _currentIndex++;\n            while (_currentIndex < _expression.Length)\n            {\n                char currentChar = _expression[_currentIndex];\n\n                // handle escaped / character\n                if (currentChar == '\\\\' && _currentIndex + 1 < _expression.Length)\n                {\n                    _currentIndex += 2;\n                }\n                else if (currentChar == '/')\n                {","sourceCodeStart":689,"sourceCodeEnd":725,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Linq/JsonPath/JPath.cs#L689-L725","documentation":"Thrown by ReadQuotedString when the closing single quote of a JSONPath string literal is never found before the end of the input string. The parser scanned forward consuming characters but ran off the end while still inside the quoted string.","triggerScenarios":"A quoted field or query value with no closing quote. Example: token.SelectTokens(\"$['firstname\") or token.SelectTokens(\"$..[?(@.name == 'bob]\") where the value quote is never terminated.","commonSituations":"Manual path strings missing the trailing quote; programmatic string assembly that drops the closing delimiter; copy/paste from a source that used smart quotes; escaping mistakes that swallow the closing quote.","solutions":["Add the missing closing single quote at the end of the field/value.","When interpolating values, always wrap with opening and closing quotes together (e.g. string.Format(\"['{0}']\", value)).","Run a quote-count or a small JSONPath linter before evaluation."],"exampleFix":"// before\ntoken.SelectTokens(\"$['firstname\");\n// after\ntoken.SelectTokens(\"$['firstname']\");","handlingStrategy":"validation","validationCode":"static bool QuotesBalanced(string path)\n{\n    int q = 0;\n    foreach (var c in path) if (c == '\\'') q++;\n    return q % 2 == 0;\n}","typeGuard":null,"tryCatchPattern":"try { token.SelectTokens(path).ToList(); }\ncatch (JsonException ex) when (ex.Message == \"Path ended with an open string.\")\n{ /* missing closing quote */ }","preventionTips":["Always add opening and closing quotes as a pair when interpolating.","Count single quotes to detect imbalance."],"tags":["jsonpath","json","parsing","jpath"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}