{"record":{"id":"6c05a1a341d416a8","repo":"JamesNK/Newtonsoft.Json","slug":"path-ended-with-open-query","errorCode":null,"errorMessage":"Path ended with open query.","messagePattern":"Path ended with open query\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Linq/JsonPath/JPath.cs","lineNumber":454,"sourceCode":"            if (_expression[_currentIndex] == '$')\n            {\n                expressionPath = new List<PathFilter> { RootFilter.Instance };\n            }\n            else if (_expression[_currentIndex] == '@')\n            {\n                expressionPath = new List<PathFilter>();\n            }\n            else\n            {\n                expressionPath = null;\n                return false;\n            }\n\n            _currentIndex++;\n\n            if (ParsePath(expressionPath!, _currentIndex, true))\n            {\n                throw new JsonException(\"Path ended with open query.\");\n            }\n\n            return true;\n        }\n\n        private JsonException CreateUnexpectedCharacterException()\n        {\n            return new JsonException(\"Unexpected character while parsing path query: \" + _expression[_currentIndex]);\n        }\n\n        private object ParseSide()\n        {\n            EatWhitespace();\n\n            if (TryParseExpression(out List<PathFilter>? expressionPath))\n            {\n                EatWhitespace();\n                EnsureLength(\"Path ended with open query.\");","sourceCodeStart":436,"sourceCodeEnd":472,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Linq/JsonPath/JPath.cs#L436-L472","documentation":"Thrown inside TryParseExpression when ParsePath returns true (consumed all remaining characters) while parsing the expression's path segment inside a query. The expression started with '$' or '@' and never reached the closing ')' of the query, so the path is truncated mid-query.","triggerScenarios":"A query indexer like [?(...)] whose inner expression path runs to the end of the string without the closing ')' or ']'. Example: token.SelectTokens(\"$..[?(@.name\") truncates after the property name.","commonSituations":"Truncated path from a clipped string; user input cut off by a length limit; templating that drops the closing delimiters; building a comparison query but forgetting the operator and right-hand side.","solutions":["Append the missing operator, right-hand value, ')' and ']' to complete the query indexer.","Add a guard that rejects paths not ending in a balanced set of brackets/parentheses before calling SelectTokens."],"exampleFix":"// before\ntoken.SelectTokens(\"$..[?(@.name\");\n// after\ntoken.SelectTokens(\"$..[?(@.name == 'bob')]\");","handlingStrategy":"validation","validationCode":"static bool EndsComplete(string path)\n{\n    var trimmed = path.TrimEnd();\n    return trimmed.EndsWith(\"]\") || trimmed.EndsWith(\"$\") || !trimmed.Contains(\"[?(\");\n}","typeGuard":null,"tryCatchPattern":"try { token.SelectTokens(path).ToList(); }\ncatch (JsonException ex) when (ex.Message == \"Path ended with open query.\")\n{ /* the query indexer is truncated; reject the input */ }","preventionTips":["Never emit '[?(' without emitting the matching ')]'.","Unit-test every generated query path against a sample token."],"tags":["jsonpath","json","parsing","jpath"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}