{"record":{"id":"ea90aad629004d5d","repo":"JamesNK/Newtonsoft.Json","slug":"array-index-expected","errorCode":null,"errorMessage":"Array index expected.","messagePattern":"Array index expected\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Linq/JsonPath/JPath.cs","lineNumber":260,"sourceCode":"            {\n                char currentCharacter = _expression[_currentIndex];\n\n                if (currentCharacter == ' ')\n                {\n                    end = _currentIndex;\n                    EatWhitespace();\n                    continue;\n                }\n\n                if (currentCharacter == indexerCloseChar)\n                {\n                    int length = (end ?? _currentIndex) - start;\n\n                    if (indexes != null)\n                    {\n                        if (length == 0)\n                        {\n                            throw new JsonException(\"Array index expected.\");\n                        }\n\n                        string indexer = _expression.Substring(start, length);\n                        int index = Convert.ToInt32(indexer, CultureInfo.InvariantCulture);\n\n                        indexes.Add(index);\n                        return new ArrayMultipleIndexFilter(indexes);\n                    }\n                    else if (colonCount > 0)\n                    {\n                        if (length > 0)\n                        {\n                            string indexer = _expression.Substring(start, length);\n                            int index = Convert.ToInt32(indexer, CultureInfo.InvariantCulture);\n\n                            if (colonCount == 1)\n                            {\n                                endIndex = index;","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Linq/JsonPath/JPath.cs#L242-L278","documentation":"Thrown by the JPath array-indexer parser when a comma-separated multi-index list reaches its closing bracket but the segment just parsed has zero length, meaning an index value was expected but missing. This is the multi-index variant at JPath.cs:256-260, triggered when indexes != null and length == 0.","triggerScenarios":"A path like token.SelectToken(\"$[1,]\") or \"$[,]\" where a comma is followed by no digits before the closing ']'. The parser records the comma, then on the ']' finds an empty index segment.","commonSituations":"Building a multi-index list dynamically and leaving a trailing comma; truncating an index expression; copy/paste leaving an empty slot.","solutions":["Remove the trailing comma so every slot has an integer index, e.g. $[1,2].","When constructing index lists programmatically, filter out empty entries before joining with commas.","Validate that each comma-separated segment is a non-negative integer."],"exampleFix":"// before\ntoken.SelectToken(\"$[1,]\");\n\n// after\ntoken.SelectToken(\"$[1]\");","handlingStrategy":"validation","validationCode":"// Build a multi-index list, dropping empty entries\nvar indices = new[] { \"1\", \"\", \"2\" }.Where(s => !string.IsNullOrEmpty(s));\nstring path = $\"$[{string.Join(\",\", indices)}]\";","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Filter empty values out of comma-separated index lists.","Validate each index segment is a non-negative integer.","Avoid trailing commas in multi-index expressions."],"tags":["jsonpath","parse-error","array-indexer"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}