{"record":{"id":"a1e9e83853074ac1","repo":"json-path/JsonPath","slug":"expected-boolean-node","errorCode":null,"errorMessage":"Expected boolean node","messagePattern":"Expected boolean node","errorType":"exception","errorClass":"InvalidPathException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/internal/filter/ValueNode.java","lineNumber":56,"sourceCode":"\n    public NumberNode asNumberNode() {\n        throw new InvalidPathException(\"Expected number node\");\n    }\n\n    public boolean isStringNode() {\n        return false;\n    }\n\n    public StringNode asStringNode() {\n        throw new InvalidPathException(\"Expected string node\");\n    }\n\n    public boolean isBooleanNode() {\n        return false;\n    }\n\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","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/internal/filter/ValueNode.java#L38-L74","documentation":"ValueNode's base asBooleanNode() throws InvalidPathException(\"Expected boolean node\") when filter evaluation calls asBooleanNode() (from evaluate/getInput) on a node that is not a BooleanNode. It indicates the filter operator required a boolean operand but the evaluated node was of another type (string, number, json, etc.). JsonPath uses this default-throw pattern on the abstract ValueNode base class.","triggerScenarios":"A filter predicate expecting a boolean operand — e.g. comparisons where one side is a boolean literal like $.items[?(@.enabled == true)] — evaluating to a non-boolean node, such as a field holding the string \"true\" instead of true, or a path resolving to a number/null.","commonSituations":"Documents serialized from string-typed sources where booleans arrive as \"true\"/\"false\" strings; flag fields missing in some records and resolving to undefined/null; mixing JavaScript-style truthy checks in filters that JsonPath does not coerce.","solutions":["Use the actual JSON boolean literal in the filter: @.enabled == true, not == 'true'","Guard the predicate so non-boolean values are excluded, e.g. $.items[?(@.enabled == true)] already excludes missing values; for string booleans normalize the data first","Coerce string \"true\"/\"false\" values to real booleans in the document before evaluation","Catch InvalidPathException around read/evaluation and handle it as a non-match"],"exampleFix":"// before\n$.items[?(@.active == 'true')]  // active is a real boolean\n// after\n$.items[?(@.active == true)]","handlingStrategy":"type-guard","validationCode":"Object v = JsonPath.parse(json).read(\"$.item.enabled\");\nif (!(v instanceof Boolean)) throw new IllegalArgumentException(\"enabled must be a JSON boolean, got: \" + v);","typeGuard":"static boolean isBooleanOperand(Object o) { return o instanceof Boolean; }","tryCatchPattern":"try {\n    return JsonPath.parse(json).read(\"$.items[?(@.enabled == true)]\");\n} catch (InvalidPathException e) {\n    return Collections.emptyList(); // non-boolean operand\n}","preventionTips":["Use true/false JSON literals in filters, never 'true'/'false' strings","Ensure serializers emit real booleans, not \"true\" strings","Exclude records with missing flags via predicate guards","Unit-test filters against documents with mixed field presence"],"tags":["jsonpath","filter","type-mismatch","boolean-node"],"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"}