{"record":{"id":"3552307c20d5f911","repo":"json-path/JsonPath","slug":"expected-predicate-node","errorCode":null,"errorMessage":"Expected predicate node","messagePattern":"Expected predicate node","errorType":"exception","errorClass":"InvalidPathException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/internal/filter/ValueNode.java","lineNumber":72,"sourceCode":"\n    public BooleanNode asBooleanNode() {\n        throw new InvalidPathException(\"Expected boolean node\");\n    }\n\n    public boolean isJsonNode() {\n        return false;\n    }\n\n    public JsonNode asJsonNode() {\n        throw new InvalidPathException(\"Expected json node\");\n    }\n\n    public boolean isPredicateNode() {\n        return false;\n    }\n\n    public PredicateNode asPredicateNode() {\n        throw new InvalidPathException(\"Expected predicate node\");\n    }\n\n    public boolean isValueListNode() {\n        return false;\n    }\n\n    public ValueListNode asValueListNode() {\n        throw new InvalidPathException(\"Expected value list node\");\n    }\n\n    public boolean isNullNode() {\n        return false;\n    }\n\n    public NullNode asNullNode() {\n        throw new InvalidPathException(\"Expected null node\");\n    }\n","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/internal/filter/ValueNode.java#L54-L90","documentation":"ValueNode's base asPredicateNode() throws InvalidPathException(\"Expected predicate node\") when evaluate calls asPredicateNode() on a node that is not a PredicateNode. PredicateNode wraps a nested [?( ... )] predicate used as an operand inside an outer filter; this error means the operand was a plain value instead of a predicate expression.","triggerScenarios":"Using a nested filter/predicate as an operand where the evaluated node is a plain ValueNode rather than a PredicateNode — i.e. the expression grammar expected [?(@.x)] as an operand but evaluation produced a scalar. Triggered from ValueNode.evaluate in the filter evaluation machinery.","commonSituations":"Complex/nested filter expressions where an inner expression was written incorrectly (missing [?()] wrapper) or an operand path resolves to a scalar instead of a predicate context; hand-built filter expressions with syntax mistakes.","solutions":["Correct the filter syntax so nested predicates are wrapped as [?( ... )], e.g. $.items[?(@.sub[?(@.ok == true)])]","Verify the operand path actually targets an array that can host a nested predicate","Simplify the expression into two sequential filter steps applied one after the other","Catch InvalidPathException around evaluation to surface a clear message about malformed predicates"],"exampleFix":"// before\n$.items[?(@.tags contains @.required == true)] // operand is scalar, not predicate\n// after\n$.items[?(@.tags[?(@ == 'x')])] // proper nested predicate form","handlingStrategy":"validation","validationCode":"// validate nested predicate syntax before evaluation\nString expr = \"$.items[?(@.tags[?(@ == 'x')])]\";\nif (!expr.contains(\"[?(\")) throw new IllegalArgumentException(\"nested predicate must be wrapped in [?( ... )]\");","typeGuard":null,"tryCatchPattern":"try {\n    return JsonPath.parse(json).read(expr);\n} catch (InvalidPathException e) {\n    throw new IllegalArgumentException(\"Malformed nested predicate in filter: \" + expr, e);\n}","preventionTips":["Always wrap nested predicates in [?( ... )]","Build complex filters incrementally and test each sub-predicate","Simplify nested filters into sequential filter steps when possible"],"tags":["jsonpath","filter","predicate","type-mismatch"],"backgroundTag":"type-mismatch","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"}