{"record":{"id":"b16800ba2805ca4c","repo":"json-path/JsonPath","slug":"expected-json-node","errorCode":null,"errorMessage":"Expected json node","messagePattern":"Expected json node","errorType":"exception","errorClass":"InvalidPathException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/internal/filter/ValueNode.java","lineNumber":64,"sourceCode":"\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\n    public boolean isValueListNode() {\n        return false;\n    }\n\n    public ValueListNode asValueListNode() {\n        throw new InvalidPathException(\"Expected value list node\");\n    }\n","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/internal/filter/ValueNode.java#L46-L82","documentation":"ValueNode's base asJsonNode() throws InvalidPathException(\"Expected json node\") when code (evaluate, vn, valueNode paths) calls asJsonNode() on a node that is not a JsonNode (a node wrapping a parsed document). This happens when a filter expects an embedded document/array operand but gets a scalar ValueNode such as a string or number. It is part of JsonPath's default-throw type-cast family on ValueNode.","triggerScenarios":"A filter or API expecting a nested document operand — e.g. an operator that calls asJsonNode() on the evaluated value of a path — receiving a scalar, e.g. $.items[?(@.meta in @.defaults)] where @.meta resolves to a string instead of an object/array. Also direct calls to valueNode()/vn conversion paths on non-document values.","commonSituations":"Comparing or nesting whole sub-documents in filters when some records store the field as a JSON string rather than a parsed object; schema drift where an array field sometimes holds a plain value.","solutions":["Ensure the operand field is a real JSON object/array in the document (parse embedded JSON strings before evaluation)","Rewrite the filter to operate on the nested field's properties rather than on the whole document value","Validate the document shape (e.g. that the field is an object) before running the filter","Catch InvalidPathException and fall back to scalar-comparison logic"],"exampleFix":"// before\nString meta = \"{}\"; // embedded JSON stored as string; filter @.meta in @.defaults fails\n// after\nObject meta = JsonPath.parse(metaJsonString).json(); // real object node; filter works","handlingStrategy":"type-guard","validationCode":"Object v = JsonPath.parse(json).read(\"$.item.meta\");\nif (!(v instanceof Map) && !(v instanceof List)) throw new IllegalArgumentException(\"meta must be a JSON object or array\");","typeGuard":"static boolean isDocumentOperand(Object o) { return o instanceof Map || o instanceof List; }","tryCatchPattern":"try {\n    return JsonPath.parse(json).read(\"$.items[?(@.meta in @.defaults)]\");\n} catch (InvalidPathException e) {\n    // operand is scalar, not a document; fallback to scalar logic\n    return fallbackScalarFilter(json);\n}","preventionTips":["Parse embedded JSON strings into real objects before filtering","Validate the document schema (object/array fields) before running document-operand filters","Avoid operators that expect whole-document operands when the field may be scalar"],"tags":["jsonpath","filter","type-mismatch","json-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"}