{"record":{"id":"e96cd73a6a1ba989","repo":"JamesNK/Newtonsoft.Json","slug":"unexpected-character-following-indexer","errorCode":null,"errorMessage":"Unexpected character following indexer: ","messagePattern":"Unexpected character following indexer: ","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Linq/JsonPath/JPath.cs","lineNumber":169,"sourceCode":"                        {\n                            scan = true;\n                            _currentIndex++;\n                        }\n                        _currentIndex++;\n                        currentPartStartIndex = _currentIndex;\n                        followingIndexer = false;\n                        followingDot = true;\n                        break;\n                    default:\n                        if (query && (currentChar == '=' || currentChar == '<' || currentChar == '!' || currentChar == '>' || currentChar == '|' || currentChar == '&'))\n                        {\n                            ended = true;\n                        }\n                        else\n                        {\n                            if (followingIndexer)\n                            {\n                                throw new JsonException(\"Unexpected character following indexer: \" + currentChar);\n                            }\n\n                            _currentIndex++;\n                        }\n                        break;\n                }\n            }\n\n            bool atPathEnd = (_currentIndex == _expression.Length);\n\n            if (_currentIndex > currentPartStartIndex)\n            {\n                string? member = _expression.Substring(currentPartStartIndex, _currentIndex - currentPartStartIndex).TrimEnd();\n                if (member == \"*\")\n                {\n                    member = null;\n                }\n                filters.Add(CreatePathFilter(member, scan));","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Linq/JsonPath/JPath.cs#L151-L187","documentation":"Thrown by the JPath parser when a character appears immediately after a closed indexer (']' or ')') without the required '.' or '[' separator. The ParsePath default branch detects the followingIndexer flag and rejects the character, because two path segments must be separated by a dot or a new indexer bracket.","triggerScenarios":"A path like token.SelectToken(\"$[0]foo\") or \"$.a[0]b\" where a field name directly follows ']' with no dot. The parser sets followingIndexer=true after the indexer and then hits the letter 'f'/'b' in the default branch (JPath.cs:167-169).","commonSituations":"Omitting the dot between an array index and the next property when hand-writing paths; string concatenation that drops a separator; converting array notation incorrectly.","solutions":["Insert a '.' between the closing bracket and the next segment, e.g. $[0].foo.","Double-check concatenated path segments include separators.","Use the indexer form $[0]['foo'] if a dot is undesirable."],"exampleFix":"// before\ntoken.SelectToken(\"$.items[0]name\");\n\n// after\ntoken.SelectToken(\"$.items[0].name\");","handlingStrategy":"validation","validationCode":"// Ensure a separator between segments when building paths\nstatic string JoinPath(params string[] segments) =>\n    string.Join(\".\", segments.Where(s => !string.IsNullOrEmpty(s)));","typeGuard":null,"tryCatchPattern":"try\n{\n    token.SelectToken(path);\n}\ncatch (JsonException ex) when (ex.Message.StartsWith(\"Unexpected character following indexer\"))\n{\n    // fix the path by inserting a '.' after the closing bracket\n}","preventionTips":["Always place a '.' between a closing bracket and the next segment.","Use a path-builder helper that inserts separators between segments.","Review concatenated paths for missing dots after indexers."],"tags":["jsonpath","parse-error","syntax"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}