{"record":{"id":"d94f791aec243af5","repo":"json-path/JsonPath","slug":"expected-wildcard-token-to-end-with-on-positio","errorCode":null,"errorMessage":"Expected wildcard token to end with ']' on position ","messagePattern":"Expected wildcard token to end with '\\]' on position ","errorType":"exception","errorClass":"InvalidPathException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/internal/path/PathCompiler.java","lineNumber":505,"sourceCode":"    //\n    // [*]\n    // *\n    //\n    private boolean readWildCardToken(PathTokenAppender appender) {\n\n        boolean inBracket = path.currentCharIs(OPEN_SQUARE_BRACKET);\n\n        if (inBracket && !path.nextSignificantCharIs(WILDCARD)) {\n            return false;\n        }\n        if (!path.currentCharIs(WILDCARD) && path.isOutOfBounds(path.position() + 1)) {\n            return false;\n        }\n        if (inBracket) {\n            int wildCardIndex = path.indexOfNextSignificantChar(WILDCARD);\n            if (!path.nextSignificantCharIs(wildCardIndex, CLOSE_SQUARE_BRACKET)) {\n                int offset = wildCardIndex + 1;\n                throw new InvalidPathException(\"Expected wildcard token to end with ']' on position \" + offset);\n            }\n            int bracketCloseIndex = path.indexOfNextSignificantChar(wildCardIndex, CLOSE_SQUARE_BRACKET);\n            path.setPosition(bracketCloseIndex + 1);\n        } else {\n            path.incrementPosition(1);\n        }\n\n        appender.appendPathToken(PathTokenFactory.createWildCardPathToken());\n\n        return path.currentIsTail() || readNextToken(appender);\n    }\n\n    //\n    // [1], [1,2, n], [1:], [1:2], [:2]\n    //\n    private boolean readArrayToken(PathTokenAppender appender) {\n\n        if (!path.currentCharIs(OPEN_SQUARE_BRACKET)) {","sourceCodeStart":487,"sourceCodeEnd":523,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/internal/path/PathCompiler.java#L487-L523","documentation":"InvalidPathException thrown by readWildCardToken when a wildcard '*' inside brackets is not immediately followed by a closing ']'. A bracketed wildcard like [*] must be terminated by ']' right after the '*'; any other character makes the path unparseable.","triggerScenarios":"Compiling paths like \"$..book[*x\" or \"$[* , ?]\" — the significant char after '*' is not ']'.","commonSituations":"Hand-edited paths where the closing bracket was deleted, dynamic concatenation of segments missing ']'.","solutions":["Ensure every bracketed wildcard is written as [*] with a closing bracket","Check for characters between '*' and ']' in the path string","Validate the assembled path with JsonPath.compile() before use"],"exampleFix":"// before\nJsonPath.read(json, \"$..book[*\")\n// after\nJsonPath.read(json, \"$..book[*]\")","handlingStrategy":"validation","validationCode":"static boolean wildcardsClosed(String path) {\n    int i = 0;\n    while ((i = path.indexOf('*', i)) != -1) {\n        if (i > 0 && path.charAt(i - 1) == '[') {\n            int j = i + 1;\n            while (j < path.length() && Character.isWhitespace(path.charAt(j))) j++;\n            if (j >= path.length() || path.charAt(j) != ']') return false;\n        }\n        i++;\n    }\n    return true;\n}","typeGuard":null,"tryCatchPattern":"try {\n    return JsonPath.read(json, path);\n} catch (InvalidPathException e) {\n    if (e.getMessage().startsWith(\"Expected wildcard token\")) {\n        throw new IllegalArgumentException(\"Wildcard '*' must be written as [*] in: \" + path);\n    }\n    throw e;\n}","preventionTips":["Always write bracketed wildcards as the exact three characters [*]","Use path builder helpers (JsonPath.builder().wildcard()) instead of raw strings","Compile paths in unit tests to catch syntax regressions"],"tags":["json-path","wildcard","path-syntax","invalid-path"],"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"}