{"record":{"id":"012f0d2428f27b04","repo":"json-path/JsonPath","slug":"expected-but-found","errorCode":null,"errorMessage":"Expected '?' but found ","messagePattern":"Expected '\\?' but found ","errorType":"exception","errorClass":"InvalidPathException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/internal/path/PathCompiler.java","lineNumber":437,"sourceCode":"        int expressionEndIndex = path.nextIndexOf(expressionBeginIndex, CLOSE_SQUARE_BRACKET);\n\n        if (expressionEndIndex == -1) {\n            return false;\n        }\n\n        String expression = path.subSequence(expressionBeginIndex, expressionEndIndex).toString();\n\n        String[] tokens = expression.split(\",\");\n\n        if (filterStack.size() < tokens.length) {\n            throw new InvalidPathException(\"Not enough predicates supplied for filter [\" + expression + \"] at position \" + path.position());\n        }\n\n        Collection<Predicate> predicates = new ArrayList<Predicate>();\n        for (String token : tokens) {\n            token = token != null ? token.trim() : null;\n            if (!\"?\".equals(token == null ? \"\" : token)) {\n                throw new InvalidPathException(\"Expected '?' but found \" + token);\n            }\n            predicates.add(filterStack.pop());\n        }\n\n        appender.appendPathToken(PathTokenFactory.createPredicatePathToken(predicates));\n\n        path.setPosition(expressionEndIndex + 1);\n\n        return path.currentIsTail() || readNextToken(appender);\n    }\n\n    //\n    // [?(...)]\n    //\n    private boolean readFilterToken(PathTokenAppender appender) {\n        if (!path.currentCharIs(OPEN_SQUARE_BRACKET) && !path.nextSignificantCharIs(BEGIN_FILTER)) {\n            return false;\n        }","sourceCodeStart":419,"sourceCodeEnd":455,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/internal/path/PathCompiler.java#L419-L455","documentation":"InvalidPathException thrown by readPlaceholderToken when a token inside a filter's placeholder expression is not the literal '?'. Positional predicate placeholders must be exactly '?'; anything else (a name, number, or typo) is rejected because the compiler cannot map it to a predicate.","triggerScenarios":"Compiling a path like \"$..book[?x]\" or \"$[ ?isTrue ]\" where the filter bracket contains a placeholder token that is not exactly '?'.","commonSituations":"Typos such as '??' fragments, whitespace-embedded tokens after splitting on commas, confusion with inline filter syntax [?(@.x == 1)] vs positional [?].","solutions":["Replace the invalid token with a plain '?' for positional predicates","Use inline filter syntax [?(@.price < 10)] instead of placeholders if you don't want external predicates","Trim and inspect the filter expression — the offending token is printed in the message"],"exampleFix":"// before\nJsonPath.read(json, \"$..book[? @.x]\")\n// after\nJsonPath.read(json, \"$..book[?(@.x)]\")","handlingStrategy":"validation","validationCode":"static boolean validPlaceholderFilter(String filterExpr) {\n    // filterExpr is the text inside [ ], e.g. \"?\" or \"? , ?\"\n    if (filterExpr.trim().isEmpty()) return false;\n    for (String tok : filterExpr.split(\",\")) {\n        if (!\"?\".equals(tok.trim())) return false;\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 '?'\")) {\n        throw new IllegalArgumentException(\"Bad placeholder token in path: \" + path);\n    }\n    throw e;\n}","preventionTips":["Remember positional placeholders are exactly '?'; inline filters use [?(@ ...)] syntax — don't mix them","Trim tokens before validating; extra words inside [ ] are rejected","Prefer inline filter expressions to avoid placeholder/token mismatches"],"tags":["json-path","filter","placeholder","invalid-path"],"backgroundTag":"invalid-argument-value","analyzedSha":"62a4c9f0f65ba3f625aa0867d64c528ba72d09ec","analyzedAt":"2026-09-11T11:36:00.448Z","contentChangedAt":"2026-09-11T11:36:00.448Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}