{"record":{"id":"b59efcbe7d401e2e","repo":"JamesNK/Newtonsoft.Json","slug":"could-not-read-query-operator","errorCode":null,"errorMessage":"Could not read query operator.","messagePattern":"Could not read query operator\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Linq/JsonPath/JPath.cs","lineNumber":820,"sourceCode":"            }\n            if (Match(\"<=\"))\n            {\n                return QueryOperator.LessThanOrEquals;\n            }\n            if (Match(\"<\"))\n            {\n                return QueryOperator.LessThan;\n            }\n            if (Match(\">=\"))\n            {\n                return QueryOperator.GreaterThanOrEquals;\n            }\n            if (Match(\">\"))\n            {\n                return QueryOperator.GreaterThan;\n            }\n\n            throw new JsonException(\"Could not read query operator.\");\n        }\n\n        private PathFilter ParseQuotedField(char indexerCloseChar, bool scan)\n        {\n            List<string>? fields = null;\n\n            while (_currentIndex < _expression.Length)\n            {\n                string field = ReadQuotedString();\n\n                EatWhitespace();\n                EnsureLength(\"Path ended with open indexer.\");\n\n                if (_expression[_currentIndex] == indexerCloseChar)\n                {\n                    if (fields != null)\n                    {\n                        fields.Add(field);","sourceCodeStart":802,"sourceCodeEnd":838,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Linq/JsonPath/JPath.cs#L802-L838","documentation":"Thrown by ParseOperator after none of the supported comparison operators (===, ==, =~, !==, !=, <>, <=, <, >=, >) matched the characters at the current position. The token where an operator was expected is not a recognized JSONPath query operator.","triggerScenarios":"A query using an unsupported or misspelled operator. Example: token.SelectTokens(\"$..[?(@.a ~= 5)]\") (~= is invalid; the regex operator is =~), or \"$..[?(@.a => 5)]\", or \"$..[?(@.a eq 5)]\" (SQL-style).","commonSituations":"Confusing JSONPath query syntax with SQL, LINQ, or JavaScript (e.g. 'eq', 'like', '=>'); transposing characters (=~ vs ~=); copy/paste from a tutorial for a different JSONPath dialect; using assignment '=' where '==' was intended.","solutions":["Use one of the supported operators: === == =~ !== != <> <= < >= >.","For equality use '==' (or '===' for strict). For regex use '=~'. For not-equal use '!=' or '<>'.","Consult the JsonSelectSettings/JSONPath query grammar reference for the exact operator set."],"exampleFix":"// before\ntoken.SelectTokens(\"$..[?(@.a ~= 5)]\");\n// after\ntoken.SelectTokens(\"$..[?(@.a == 5)]\");","handlingStrategy":"validation","validationCode":"static readonly HashSet<string> ValidOps = new()\n{ \"===\",\"==\",\"=~\",\"!==\",\"!=\",\"<>\",\"<=\",\"<\",\">=\",\">\" };\nstatic bool UsesValidOperator(string path)\n{\n    foreach (var op in ValidOps) if (path.Contains(op)) return true;\n    return !path.Contains(\"[?(\");\n}","typeGuard":null,"tryCatchPattern":"try { token.SelectTokens(path).ToList(); }\ncatch (JsonException ex) when (ex.Message == \"Could not read query operator.\")\n{ /* unsupported operator used; show the valid set to the user */ }","preventionTips":["Memorize the operator set: === == =~ !== != <> <= < >= >.","For regex use '=~', never '~='."],"tags":["jsonpath","json","parsing","jpath"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}