{"record":{"id":"a95000197f36c919","repo":"json-path/JsonPath","slug":"failed-to-parse-arrayindexoperation","errorCode":null,"errorMessage":"Failed to parse ArrayIndexOperation: ","messagePattern":"Failed to parse ArrayIndexOperation: ","errorType":"exception","errorClass":"InvalidPathException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/internal/path/ArrayIndexOperation.java","lineNumber":46,"sourceCode":"        return indexes.size() == 1;\n    }\n\n    @Override\n    public String toString() {\n        StringBuilder sb = new StringBuilder();\n        sb.append(\"[\");\n        sb.append(Utils.join(\",\", indexes));\n        sb.append(\"]\");\n\n        return sb.toString();\n    }\n\n    public static ArrayIndexOperation parse(String operation) {\n        //check valid chars\n        for (int i = 0; i < operation.length(); i++) {\n            char c = operation.charAt(i);\n            if (!isDigit(c) && c != ',' && c != ' ' && c != '-') {\n                throw new InvalidPathException(\"Failed to parse ArrayIndexOperation: \" + operation);\n            }\n        }\n        String[] tokens = COMMA.split(operation, -1);\n\n        List<Integer> tempIndexes = new ArrayList<Integer>(tokens.length);\n        for (String token : tokens) {\n            tempIndexes.add(parseInteger(token));\n        }\n\n        return new ArrayIndexOperation(tempIndexes);\n    }\n\n    private static Integer parseInteger(String token) {\n        try {\n            return Integer.parseInt(token);\n        } catch (Exception e){\n            throw new InvalidPathException(\"Failed to parse token in ArrayIndexOperation: \" + token, e);\n        }","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/internal/path/ArrayIndexOperation.java#L28-L64","documentation":"ArrayIndexOperation.parse() validates that an array-index operation string (the content of brackets like [1,2,-3]) contains only digits, commas, spaces, and minus signs. Any other character causes InvalidPathException('Failed to parse ArrayIndexOperation: <operation>').","triggerScenarios":"A path segment like [$[?(@.x)])] misuse or bracket content with illegal chars — e.g. [a], [1:2] fragments misrouted to this parser, [1,2;3], or brackets containing letters/colons — reaching the array-index parser during Path compilation.","commonSituations":"Typo'd filter/index syntax (mixing [?(@..)] with plain index brackets), slicing syntax with unexpected tokens, dynamically built paths where user input flows into brackets, or locale-formatted numbers with separators.","solutions":["Ensure bracket content is a comma-separated list of integers, e.g. [0,2,-1].","Use filter syntax [?(@.field == 'x')] instead of putting expressions inside plain index brackets.","Sanitize/validate any user-supplied path fragments before compiling with JsonPath.compile().","Catch InvalidPathException and report which bracket segment failed."],"exampleFix":"// before\nJsonPath.read(json, \"$.items[a,b]\"); // invalid chars in index op\n// after\nJsonPath.read(json, \"$.items[0,1]\");","handlingStrategy":"validation","validationCode":"if (!operation.matches(\"[-0-9, ]*\")) throw new InvalidPathException(\"Invalid array index operation: \" + operation);","typeGuard":null,"tryCatchPattern":"try {\n    JsonPath.compile(path);\n} catch (InvalidPathException e) {\n    if (e.getMessage().startsWith(\"Failed to parse ArrayIndexOperation\")) { /* fix bracket content */ }\n    throw e;\n}","preventionTips":["Only digits, commas, spaces, and minus signs belong in plain index brackets","Use [?(@...)] filter syntax for expressions, not []","Sanitize dynamic/user-supplied path segments"],"tags":["json-path","invalid-path","syntax"],"backgroundTag":"invalid-argument-format","analyzedSha":"62a4c9f0f65ba3f625aa0867d64c528ba72d09ec","analyzedAt":"2026-09-11T11:36:00.448Z","contentChangedAt":"2026-09-11T11:36:00.448Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}